0 votes
by (160 points)

We are using Rebex libraries to connect to an SFTP server. On one client site, the following error is returned at PutFile:

Rebex.Net.SftpException: No such file; No such file. at Rebex.Net.ZEB.EC(TDB A, Type B) at Rebex.Net.ZEB.HB(String A, WFB B, Boolean C, CEB D) at Rebex.Net.Sftp.AAB(WFB A, CEB B, String C, Stream D, Int64 E, Int64 H, XCB I) at Rebex.Net.Sftp.AAB(WFB A, CEB B, String C, String D, Int64 E, Int64 H, Int64 I, XCB J) at Rebex.Net.Sftp.ZZ(WFB A, String B, String C, Int64 D, Int64 E, Int64 H, XCB I) at Rebex.Net.Sftp.PutFile(String localPath, String remotePath)

Below is the logwriter verbose output. Please advise as to how we can resolve this error.

2015-08-04 12:48:32.923 Opening log file.
2015-08-04 12:48:32.923 Using FileLogWriter version 2.0.4981.0.
2015-08-04 12:48:32.939 VERBOSE Sftp(1)[14] SSH: Sending packet SSHMSGCHANNELDATA (45 bytes).
0000 |5E-00-00-00-00-00-00-00 24-00-00-00-20-11-00-00| ^.......$... ...
0010 |00-02-00-00-00-17-2F-75 70-6C-6F-61-64-2F-75-70| ....../upload/up
0020 |6C-6F-61-64-2F-74-65-73 74-2E-70-64-66 | load/test.pdf
2015-08-04 12:48:32.939 INFO Sftp(1)[14] Command: SSH
FXPSTAT (2, '/upload/upload/test.pdf')
2015-08-04 12:48:32.954 VERBOSE Sftp(1)[14] SSH: Received packet SSH
MSGCHANNELDATA (42 bytes).
0000 |5E-00-00-00-00-00-00-00 21-00-00-00-1D-65-00-00| ^.......!....e..
0010 |00-02-00-00-00-02-00-00 00-0C-4E-6F-20-73-75-63| ..........No suc
0020 |68-20-66-69-6C-65-00-00 00-00 | h file....
2015-08-04 12:48:32.954 INFO Sftp(1)[14] Response: SSHFXPSTATUS (2, 2, 'No such file')
2015-08-04 12:48:32.985 VERBOSE Sftp(1)[14] SSH: Sending packet SSHMSGCHANNELDATA (53 bytes).
0000 |5E-00-00-00-00-00-00-00 2C-00-00-00-28-03-00-00| ^.......,...(...
0010 |00-03-00-00-00-17-2F-75 70-6C-6F-61-64-2F-75-70| ....../upload/up
0020 |6C-6F-61-64-2F-74-65-73 74-2E-70-64-66-00-00-00| load/test.pdf...
0030 |1A-00-00-00-00 | .....
2015-08-04 12:48:32.985 INFO Sftp(1)[14] Command: SSH
FXPOPEN (3, '/upload/upload/test.pdf', 26)
2015-08-04 12:48:33.017 VERBOSE Sftp(1)[14] SSH: Received packet SSH
MSGCHANNELDATA (42 bytes).
0000 |5E-00-00-00-00-00-00-00 21-00-00-00-1D-65-00-00| ^.......!....e..
0010 |00-03-00-00-00-02-00-00 00-0C-4E-6F-20-73-75-63| ..........No suc
0020 |68-20-66-69-6C-65-00-00 00-00 | h file....
2015-08-04 12:48:33.017 INFO Sftp(1)[14] Response: SSHFXPSTATUS (3, 2, 'No such file')
2015-08-04 12:48:33.017 ERROR Sftp(1)[14] Info: Rebex.Net.SftpException: No such file; No such file.
at Rebex.Net.ZEB.EC(TDB A, Type B)
at Rebex.Net.ZEB.HB(String A, WFB B, Boolean C, CEB D)
at Rebex.Net.Sftp.AAB(WFB A, CEB B, String C, Stream D, Int64 E, Int64 H, XCB I)
2015-08-04 12:48:33.032 VERBOSE Sftp(1)[14] SSH: Sending packet SSHMSGCHANNELEOF (5 bytes).
0000 |60-00-00-00-00 | `....
2015-08-04 12:48:33.032 VERBOSE Sftp(1)[14] SSH: Sending packet SSH
MSGCHANNELCLOSE (5 bytes).
0000 |61-00-00-00-00 | a....
2015-08-04 12:48:33.063 VERBOSE Sftp(1)[14] SSH: Received packet SSHMSGCHANNELREQUEST (25 bytes).
0000 |62-00-00-00-00-00-00-00 0B-65-78-69-74-2D-73-74| b........exit-st
0010 |61-74-75-73-00-00-00-00 00 | atus.....
2015-08-04 12:48:33.063 VERBOSE Sftp(1)[14] SSH: Received packet SSH
MSGCHANNELCLOSE (5 bytes).
0000 |61-00-00-00-00 | a....
2015-08-04 12:48:33.063 VERBOSE Sftp(1)[14] SSH: Sending packet SSHMSGDISCONNECT (27 bytes).
0000 |01-00-00-00-0B-00-00-00 0E-53-65-73-73-69-6F-6E| .........Session
0010 |20-63-6C-6F-73-65-64-00 00-00-00 | closed....

Applies to: Rebex SFTP

1 Answer

0 votes
by (58.9k points)

Hello,

I have noticed that you are uploading "test.pdf" file to the SFTP server into the "/upload/upload/" remote directory. Please note that the PutFile method does not automatically create the remote folders in case they are not existing. Moreover, we have already encountered some SFTP servers reporting the "No such file" error in the case when the directory to which the file should be uploaded to does not exist.

So please try to check whether the directory exists (using the Sftp.DirectoryExists method) before calling the PutFile method.

Here is a short code snippet, please give it a try and let me know whether it helped to resolve your issue.

Sftp sftp = new Sftp();
sftp.Connect("server", 22);
sftp.Login("user", "password");

sftp.ChangeDirectory("/");

if (!sftp.DirectoryExists("upload"))
    sftp.CreateDirectory("upload");

sftp.ChangeDirectory("upload");

if (!sftp.DirectoryExists("upload"))
    sftp.CreateDirectory("upload");

sftp.ChangeDirectory("upload");

sftp.PutFile("test.pdf", @"C:\myData\test.pdf");

sftp.Disconnect();
by (160 points)
Thanks for the response.

We will try this but the directory exists on the server. We are not trying to create a new folder.

We actually were trying to upload the file to the "upload" directory, not "upload/upload". We noticed that Rebex was adding an additional "upload" directory to the path.

Our code explicitly states that the path should be "ftp.server.com/upload", not "ftp.server.com/upload/upload".
by (58.9k points)
Ok, thanks for your clarification. Sorry it is not possible to specify the upload dir via a SFTP server URL. If you want to specify the upload directory, you can do it via ChangeDirectory method or directly within the PutFile method.Please try the code below and let me know whether it helped:


                        Sftp sftp = new Sftp();
            sftp.Connect("sftp.server.com", 22); // there is no way to specify the upload directory in the connect method
            sftp.Login("user", "password");

            // to specify the upload dir you have two possibilities:
            // 1] either change to the upload directory and then the PutFile method will upload to the current directory like this:
            sftp.ChangeDirectory("/upload");
            sftp.PutFile(@"C:\myData\test.pdf", "test.pdf");

            // 2] or just use the full path (including the upload directory)
            // like this:
            sftp.PutFile(@"C:\myData\test.pdf", "/upload/test.pdf");

I hope both two short code examples should work for you and Rebex definitely should not be adding an additional subdirectory to your specified parameters. If you still see the additional 'upload' directory with My code snippets above , please post or send to  the log of the communication.
by (160 points)
Thanks.

Using ChangeDirectory worked and through that we determined that the directory did not exist.

The problem is that when using PutFile to pass the upload directory and file name, we received an exception that was not accurate: No such file.

An more appropriate error message would have been : Directory or path not found
by (58.9k points)
Good to hear you resolved it. As to your suggestion, unfortunatelly the error is reported by the SFTP server as can be seen in the log so we have no control over it:

2015-08-04 12:48:32.954 INFO Sftp(1)[14] Response: SSHFXPSTATUS (2, 2, 'No such file')

If you want to have it solved, please report the suggestion for a better error message to the SFTP server vendor.
...