vba - Creating folder in ftp server -
i have vbscript file see below:
set oshell = createobject("shell.application") set objfso = createobject("scripting.filesystemobject") set objsb = createobject("system.text.stringbuilder") yesterday = dateadd("d", -1, date) foldername = sprintf("{0:yyyymmdd}", array(yesterday)) & ".opentrades" fullpath = "c:\test\" & foldername call ftpupload(fullpath, foldername) sub ftpupload(fullpath, foldername) const copytype = 16 waittime = 80000 ftpuser = "username" ftppass = "password" ftphost = "hostname" ftpdir = "/1/" strftp = "ftp://" & ftpuser & ":" & ftppass & "@" & ftphost & ftpdir set objftp = oshell.namespace(strftp) 'upload files in folder if objfso.folderexists(fullpath) set objfolder = oshell.namespace(fullpath) wscript.echo "uploading folder " & fullpath & " " & strftp objftp.copyhere objfolder.items, copytype end if if err.number <> 0 wscript.echo "error: " & err.description end if 'wait upload wscript.sleep waittime end sub function sprintf(sfmt, adata) objsb.appendformat_4 sfmt, (adata) sprintf = objsb.tostring() objsb.length = 0 end function
the script copies files in specified directory (fullpath variable) target directory (ftpdir variable). want create new folder having name stored in foldername variable in ftp server , copy files newly created folder. i'm new vbscript , open advices.
thanks in advance,
replace line set objfolder = oshell.namespace(fullpath)
with
set objfolder = oshell.namespace(objfso.getparentfoldername(fullpath))
and objftp.copyhere objfolder.items, copytype
with
objftp.copyhere objfolder.parsename(objfso.getfilename(fullpath)), copytype
then should work.
with this, local namespace parent folder of fullpath
, foldername
item copied remote directory.
Comments
Post a Comment