Check if remote file exists before upload - WeOnlyDo Discussion board

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

by Limey, Wednesday, September 10, 2014, 17:13 (3513 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

Check if remote file exists before upload

by wodSupport, Wednesday, September 10, 2014, 17:16 (3513 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

Check if remote file exists before upload

by Limey, Wednesday, September 10, 2014, 18:02 (3513 days ago) @ wodSupport

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

Check if remote file exists before upload

by wodSupport, Wednesday, September 10, 2014, 18:04 (3513 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

Check if remote file exists before upload

by Limey, Wednesday, September 10, 2014, 19:59 (3513 days ago) @ wodSupport

I'm trying to use this process (in c#)

http://example.weonlydo.com/?did=Directory-listing-using-SFTP-protocol


Whenever it tries to do ListAttributes, I get a "Timeout occurred due to inactivity."

any suggestions?

Check if remote file exists before upload

by Limey, Wednesday, September 10, 2014, 20:01 (3513 days ago) @ Limey

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

Check if remote file exists before upload

by wodSupport, Wednesday, September 10, 2014, 20:08 (3513 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

Check if remote file exists before upload

by Limey, Wednesday, September 10, 2014, 20:14 (3513 days ago) @ wodSupport

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.

Check if remote file exists before upload

by wodSupport, Wednesday, September 10, 2014, 20:15 (3513 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