0 votes
by (120 points)
edited

As the title says... is it possible to upload a file from a network drive to an SFTP server? I tried using your library, but although I could connect successfully, I couldn't upload a file from a network drive. I got this quite unhelpful error:

SftpException: "No such file; No such file."

I must stress that there WAS a file present and in fact, I WAS able to upload the SAME file after I moved it to the C drive. However, for my project, it is absolutely imperative that I can upload from network folders, rather than the C drive. Can you please tell me how to proceed?

Kind regards,

Sheridan Yuen


UPDATE >>>

Here is the log for the failed operation:

2014-03-18 14:50:32.853 Opening log file.
2014-03-18 14:50:32.853 Using FileLogWriter version 2.0.5171.0.
2014-03-18 14:50:32.870 INFO Sftp(1)[17] Info: Connecting to sftp.dmm.content.sonydadc.com:22 using Sftp 3.0.5171.0 (trial version). 
2014-03-18 14:50:32.989 DEBUG Sftp(1)[17] SSH: Server is 'SSH-2.0-OpenSSH_5.9'. 
2014-03-18 14:50:32.991 INFO Sftp(1)[17] SSH: Negotiation started.
2014-03-18 14:50:33.034 DEBUG Sftp(1)[17] SSH: Group exchange. 
2014-03-18 14:50:33.096 DEBUG Sftp(1)[17] SSH: Negotiating key. 
2014-03-18 14:50:33.306 DEBUG Sftp(1)[17] SSH: Validating signature. 
2014-03-18 14:50:33.317 INFO Sftp(1)[17] SSH: Negotiation finished. 
2014-03-18 14:50:33.317 INFO Sftp(1)[17] Info: Server: SSH-2.0-OpenSSH_5.9
2014-03-18 14:50:33.317 INFO Sftp(1)[17] Info: Fingerprint: d5:99:1d:b3:10:f4:8d:5f:4d:3b:df:07:b8:74:84:e8 
2014-03-18 14:50:33.317 INFO Sftp(1)[17] Info: Cipher info: SSH 2.0, DiffieHellmanGroupExchangeSHA256, DSS, aes256-ctr/aes256-ctr, hmac-sha1/hmac-sha1
2014-03-18 14:50:33.385 DEBUG Sftp(1)[17] SSH: Allowed authentication methods: publickey, password, keyboard-interactive. 
2014-03-18 14:50:33.386 DEBUG Sftp(1)[17] SSH: Trying password authentication for 'mosftp'. 
2014-03-18 14:50:33.412 DEBUG Sftp(1)[17] SSH: Authentication successful. 
2014-03-18 14:50:33.442 DEBUG Sftp(1)[17] SSH: Requesting subsystem 'sftp'. 
2014-03-18 14:50:33.480 INFO Sftp(1)[17] Command: SSH_FXP_INIT (4) 
2014-03-18 14:50:33.506 INFO Sftp(1)[17] Response: SSH_FXP_VERSION (3, 4 extensions)
2014-03-18 14:50:33.507 INFO Sftp(1)[17] Info: Using SFTP v3 on a Unix-like platform.
2014-03-18 14:50:33.509 INFO Sftp(1)[17] Command: SSH_FXP_REALPATH (1, '.')
2014-03-18 14:50:33.534 INFO Sftp(1)[17] Response: SSH_FXP_NAME (1, 1 item) 
2014-03-18 14:50:33.534 INFO Sftp(1)[17] Info: Current directory is '/dropboxes/mos_ingest'.
2014-03-18 14:50:33.561 INFO Sftp(1)[17] Command: SSH_FXP_OPEN 2, '/assets/mos_assets/inbox/506689696295', 26) 
2014-03-18 14:50:33.586 INFO Sftp(1)[17] Response: SSH_FXP_STATUS (2, 2, 'No such file') 
2014-03-18 14:50:33.622 ERROR Sftp(1)[17] Info: Rebex.Net.SftpException: No such file; No such file.    
    at Rebex.Net.MFB.EC(GEB A, Type B)
    at Rebex.Net.MFB.HB(String A, JGB B, Boolean C, PEB D)
    at Rebex.Net.Sftp.VAB(JGB A, PEB B, String C, Stream D, Int64 E, Int64 H, IDB I)

I should also like to correct my initial question... I was NOT able to upload the file from the C drive either.


UPDATE 2 >>>

You suggested checking that the folder is actually there... I can see it there in Filezilla and can upload or download files from it and to it using that application. Unfortunately, your code is telling me that it doesn't exist. Basically, the relative server path should be /assets/mos_assets/inbox and the folder name that is definitely present is 506689696295. Here is the new log:

2014-03-18 15:45:06.253 Opening log file.
2014-03-18 15:45:06.253 Using FileLogWriter version 2.0.5171.0.
2014-03-18 15:45:06.266 INFO Sftp(1)[15] Info: Connecting to sftp.dmm.content.sonydadc.com:22 using Sftp 3.0.5171.0 (trial version).
2014-03-18 15:45:06.387 DEBUG Sftp(1)[15] SSH: Server is 'SSH-2.0-OpenSSH_5.9'.
2014-03-18 15:45:06.388 INFO Sftp(1)[15] SSH: Negotiation started.
2014-03-18 15:45:06.430 DEBUG Sftp(1)[15] SSH: Group exchange.
2014-03-18 15:45:06.477 DEBUG Sftp(1)[15] SSH: Negotiating key.
2014-03-18 15:45:06.695 DEBUG Sftp(1)[15] SSH: Validating signature.
2014-03-18 15:45:06.705 INFO Sftp(1)[15] SSH: Negotiation finished.
2014-03-18 15:45:06.705 INFO Sftp(1)[15] Info: Server: SSH-2.0-OpenSSH_5.9
2014-03-18 15:45:06.706 INFO Sftp(1)[15] Info: Fingerprint: d5:99:1d:b3:10:f4:8d:5f:4d:3b:df:07:b8:74:84:e8
2014-03-18 15:45:06.706 INFO Sftp(1)[15] Info: Cipher info: SSH 2.0, DiffieHellmanGroupExchangeSHA256, DSS, aes256-ctr/aes256-ctr, hmac-sha1/hmac-sha1
2014-03-18 15:45:06.771 DEBUG Sftp(1)[15] SSH: Allowed authentication methods: publickey, password, keyboard-interactive.
2014-03-18 15:45:06.772 DEBUG Sftp(1)[15] SSH: Trying password authentication for 'mosftp'.
2014-03-18 15:45:06.797 DEBUG Sftp(1)[15] SSH: Authentication successful.
2014-03-18 15:45:06.831 DEBUG Sftp(1)[15] SSH: Requesting subsystem 'sftp'.
2014-03-18 15:45:06.869 INFO Sftp(1)[15] Command: SSH_FXP_INIT (4)
2014-03-18 15:45:06.897 INFO Sftp(1)[15] Response: SSH_FXP_VERSION (3, 4 extensions)
2014-03-18 15:45:06.897 INFO Sftp(1)[15] Info: Using SFTP v3 on a Unix-like platform.
2014-03-18 15:45:06.900 INFO Sftp(1)[15] Command: SSH_FXP_REALPATH (1, '.')
2014-03-18 15:45:06.927 INFO Sftp(1)[15] Response: SSH_FXP_NAME (1, 1 item)
2014-03-18 15:45:06.927 INFO Sftp(1)[15] Info: Current directory is '/dropboxes/mos_ingest'.
2014-03-18 15:45:06.932 INFO Sftp(1)[15] Command: SSH_FXP_STAT (2, '/assets/mos_assets/inbox/506689696295')
2014-03-18 15:45:06.960 INFO Sftp(1)[15] Response: SSH_FXP_STATUS (2, 2, 'No such file')
2014-03-18 15:45:06.963 INFO Sftp(1)[15] Command: SSH_FXP_MKDIR (3, '/assets/mos_assets/inbox/506689696295')
2014-03-18 15:45:06.989 INFO Sftp(1)[15] Response: SSH_FXP_STATUS (3, 2, 'No such file')
2014-03-18 15:45:07.073 ERROR Sftp(1)[15] Info: Rebex.Net.SftpException: No such file; No such file.
   at Rebex.Net.MFB.EC(GEB A, Type B)
   at Rebex.Net.MFB.WB(String A, PEB B)
   at Rebex.Net.Sftp.XO(String A, PEB B)
Applies to: Rebex SFTP

2 Answers

0 votes
by (58.9k points)
edited

Well, the SftpException ("No such file; No such file.") you got doesn't have anything to do with the source file which you are trying to upload (located on the network drive in your case), but rather with the remote file on the SFTP server.

Would it be possible to create a log of communication and then either upload it here or send it to support@rebex.net? It would help us to find out what is the actual problem and hopefully solve this issue. Thank you!

0 votes
by (58.9k points)
edited

Thank you for the log file. From it we have found out that OpenSSH server reports the "No such file." message, if you are trying to upload a file into a non-existing remote directory.

The solution would be to check for the directory existence and if it does not exist, create the remote directory before uploading a file into it. Here is a code which does that:

Sftp sftp = new Sftp();
sftp.Connect("sftp.dmm.content.sonydadc.com");
sftp.Login("user", "password");

if (!sftp.DirectoryExists("/assets/mos_assets/inbox"))
    sftp.CreateDirectory("/assets/mos_assets/inbox");

sftp.PutFile(@"C:\MyData\file.txt", "/assets/mos_assets/inbox/file.txt");

sftp.Disconnect();

So in your case the error did not have anything to do with network drive, but rather with the remote SFTP server. Network drives can be normally used with Rebex components. Please test the above code and let us know whether the problem is resolved. Thanks!

...