Check if remote file exists before upload (wodSFTP / wodSFTP.NET / wodSFTPdll)

by Limey, (3887 days ago)

Hi,

I'm trying to verify if a file exists on the remote SFTP server before I upload, so I can decide if I want to overwrite or not.

I'm assuming I would do this in the loopEvent, as I am using PutFiles() to copy the files.


thanks

locked

Check if remote file exists before upload

by Jasmine, (3887 days ago) @ Limey

Hi.

I suggest you use GetAttributes method

http://www.weonlydo.com/SFTP/Help/wodSFTP-GetAttributes.html

for each file before the upload. If it returns an error - then file doesn't exist.

But you cannot use it in LoopItem event, since LoopItem fires while some other method is processing. You must wait for Done to complete in order to execute GetAttributes, so you should do it before GetFiles/PutFiles.

Kreso

locked

Check if remote file exists before upload

by Limey, (3887 days ago) @ Jasmine

I'm a little lost.

If I'm using putfiles() to copy a directory, how is calling Get Attributes on my instance of wodSFTP checking every file?

do you have an example of this you could provide?

Thanks

locked

Check if remote file exists before upload

by Jasmine, (3887 days ago) @ Limey

Hi.

You cannot use GetAttributes inside PutFiles, that's what I mentioned that is a problem. Rather, I would use ListDir to list directory contents, and then parse and put existing files in some local list.

Then in PutFiles check if there is a file in my local list, and that way determine if it exists on remote side or not.

There is no automated way to do this.

Kreso

locked

Check if remote file exists before upload

by Limey, (3887 days ago) @ Limey

should also note that I tried setting the timeout to zero, and then it just waits forever.

locked

Check if remote file exists before upload

by Jasmine, (3887 days ago) @ Limey

Hi.

ListAttributes is very similar to ListDir (same, under the hood). I don't see a reason it would fail. Does getting directory listing works using ListDir, or using some other SFTP client (such as FileZilla)?

Kreso

locked

Check if remote file exists before upload

by Limey, (3887 days ago) @ Jasmine

well, I found that it doesn't seem to like ListAttributes being in the connectedEvent. Once I removed the event and just called ListAtributes before the PutFiles method, I was able to get results (while still using AttributesDataEvent.

locked

Check if remote file exists before upload

by Jasmine, (3887 days ago) @ Limey

Are you using Blocking = 1 ? If so, don't use any methods inside events, since everything will block (and eventually Timeout).

Kreso

locked