0 votes
by (120 points)
edited by

Hello

I try to get files from server in SFTP and i have no problem Download an xml file but for others files i have this error :

Exception message : "Failure; Error opening/creating file /Label/20160325_Format_1.prn."

In Log :

2016-10-24 10:57:20 Opening log file.
2016-10-24 10:57:20 Using FileLogWriter version 2.0.6083.0.
2016-10-24 10:57:22 INFO Sftp(1)[1802216234] Command: SSH_FXP_REALPATH (2, '/Label/')
2016-10-24 10:57:22 INFO Sftp(1)[1802216234] Response: SSH_FXP_NAME (2, 1 item)
2016-10-24 10:57:22 INFO Sftp(1)[1802216234] Command: SSH_FXP_STAT (3, '/Label')
2016-10-24 10:57:23 INFO Sftp(1)[1802216234] Response: SSH_FXP_ATTRS (3)
2016-10-24 10:57:23 INFO Sftp(1)[1802216234] Command: SSH_FXP_OPENDIR (4, '/Label')
2016-10-24 10:57:23 INFO Sftp(1)[1802216234] Response: SSH_FXP_HANDLE (4, 0x0)
2016-10-24 10:57:23 INFO Sftp(1)[1802216234] Command: SSH_FXP_READDIR (5, 0x0)
2016-10-24 10:57:23 INFO Sftp(1)[1802216234] Response: SSH_FXP_NAME (5, 9 items)
2016-10-24 10:57:23 INFO Sftp(1)[1802216234] Command: SSH_FXP_READDIR (6, 0x0)
2016-10-24 10:57:23 INFO Sftp(1)[1802216234] Response: SSH_FXP_STATUS (6, 1, 'No files')
2016-10-24 10:57:23 INFO Sftp(1)[1802216234] Command: SSH_FXP_CLOSE (7, 0x0)
2016-10-24 10:57:23 INFO Sftp(1)[1802216234] Response: SSH_FXP_STATUS (7, 0, '')
2016-10-24 10:57:24 INFO Sftp(1)[1802216234] Command: SSH_FXP_OPEN (8, '/Label/20160325_Format_1.prn', 1)
2016-10-24 10:57:24 INFO Sftp(1)[1802216234] Response: SSH_FXP_STATUS (8, 4, 'Error opening/creating file /Label/20160325_Format_1.prn')
2016-10-24 10:57:24 ERROR Sftp(1)[1802216234] Info: Rebex.Net.SftpException: Failure; Error opening/creating file /Label/20160325_Format_1.prn.
à Rebex.Net.AFD.YG(AZD HU, Type UU)
à Rebex.Net.AFD.UG(String HU, UKD UU, Boolean GU, KZD AU)
à Rebex.Net.Sftp.PY(KZD HU, String UU, Stream GU, Int64 AU, Int64 IU, BDD DU)
à Rebex.Net.Sftp.PY(FileMode HU, KZD UU, String GU, String AU, Int64 IU, Int64 DU, Int64 SU, BDD ZU)
à Rebex.Net.Sftp.AY(FileMode HU, String UU, String GU, Int64 AU, Int64 IU, Int64 DU, BDD SU)
à Rebex.Net.Sftp.GetFile(String remotePath, String localPath)
à MtcFtp.MtcFtp.ftpGetFile(String filename)
à AutoUpdaterDotNET.AutoUpdater.WaitCallBackDoWork(Object sender)
à System.Threading.ThreadPool.WorkItem.doWork(Object o)
à System.Threading.Timer.ring()

I'm sure the file exist, there is no need to create.
With another SFTP lib, i haven't this problem.

Best regards

Applies to: Rebex SFTP

1 Answer

0 votes
by (58.9k points)

Hi,

if some of the downloaded files already exist, and you want to overwrite them just use the ActionOnExistingFiles parameter:

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

sftp.Download("remotePath", "localPath", 0, 0, ActionOnExistingFiles.OverwriteAll);
sftp.Disconnect();
by (120 points)
Hello,  i have the same error  with your example.
This problem is not in local to rewrite the file, it's on the remote file.

Thanks
by (58.9k points)
The server does not allow the file to be opened. Are you able to download the file with a third party SFTP client?
by (120 points)
Yes, I can download the same files with another SFTP client.
by (58.9k points)
Could you please try the following code on the problematic file and let me know whether it is able to download the file:

            var client = new Sftp();
            client.Connect("server");
            client.Login("user", "password");

            try
            {
                string remoteFile = "/Label/20160325Format1.prn";
                string localFile = @"C:\temp\20160325Format1.prn";
                bool fileExists = client.FileExists(remoteFile);

                // download the file directly (full path used)
                Console.WriteLine("File exists {0}", fileExists);
                client.GetFile(remoteFile, localFile);
                Console.WriteLine("Download was succesful.");
            }
            catch (SftpException ex)
            {
                Console.WriteLine(ex.ToString());
            }
by (120 points)
Hello

I tried your code and i have still the same problem (Error Opening/Creating File), but the file exists.
I forgot to say, i'm on the PDA Windows Mobile.
by (147k points)
Hello, and thanks!

Could you please post a from the code with FileExists as well?

Also, it might help us a lot if you named the SFTP server you use and the SFTP client that was able to download the file. If we were able to reproduce this behavior, I'm sure we could solve it within hours.
...