0 votes
by (450 points)
edited

Hello Guys,

I have a question regarding SFTP Upload. Here's the scenario:

In my local machine I have the following files to upload

Local Machine

C:\ForUpload\1\File_1_Full.zip
C:\ForUpload\1\File_1_Full.MD5
C:\ForUpload\2\File_2_Full.zip
C:\ForUpload\2\File_2_Full.MD5
C:\ForUpload\FileIndex.xml


Target Remote Location

/myserver


Question:
What function should I use to perform batch upload instead of specifying each file to upload I will just use patterns and then it will recursively loop through and find the pattern from source and upload to destination. like put("c:\ForUpload\\*.zip", "/myserver", SftpBatchTransferOptions.XCopy, SftpActionOnExistingFiles.OverwriteAll)


Expected Result:

/myServer/File_1_Full.zip
/myServer/File_1_Full.MD5
/myServer/File_2_Full.zip
/myServer/File_2_Full.MD5
/myServer/FileIndex.xml
Applies to: Rebex SFTP

1 Answer

+1 vote
by (73.6k points)
edited
 
Best answer

Unfortunately, this is too much complicated condition. It is not possible to do it by using wildcard patterns only.

Moreover you want to achieve a special task: transfer file without persisting original file hierarchy (you want to upload all files from different directories to a single target directory '/myServer' all together). This is not possible to do it in current version, but it is a reasonable behaviour, so we will probably add it to one of the future versions.

For now you have to split the task into multiple batch transfers. The given example can be achieved like this:

ftp.PutFiles("c:\ForUpload\1\File_*_Full.*", "/myServer", FtpBatchTransferOptions.Default);
ftp.PutFiles("c:\ForUpload\2\File_*_Full.*", "/myServer", FtpBatchTransferOptions.Default);
ftp.PutFiles("c:\ForUpload\FileIndex.xml", "/myServer", FtpBatchTransferOptions.Default);

This will transfer the 'c:\ForUpload\FileIndex.xml' file and all files (which name suits the pattern File_*_Full.*) from the 'c:\ForUpload\1' and 'c:\ForUpload\2' directories. Please note that this also transfer files like 'c:\ForUpload\1\File_5_Full.txt' (all file extensions meet the file name check).

...