0 votes
by (150 points)
edited

I observe an interesting behaviour. There are two .net 2.0 assemblies that use Rebex Rebex.Net component to send files to an SFTP server. One works fine, VB.NET, but the other, C# doesn't. I am able to login to the server, locate the destination folder, but get an exeption o PutFile method. They both called by the same Windows .net 2.0 VB.NET application. Insights are very welcome. Thank you.

private SftpFileSentStatus SendSftpTestFile(MGAManager mga, string pFileName, string sURI)
{
    SftpFileSentStatus fileTransferStatus = SftpFileSentStatus.None;
    Sftp client = null;
    if (System.IO.File.Exists(pFileName))
    {
        try
        {
            client = new Sftp();
            client.Connect(mga.FTPServer);
            client.Login(mga.FTPUser, mga.FTPPassword);
            client.PutFile(pFileName, sURI);
            fileTransferStatus = SftpFileSentStatus.Success;

        }
        catch (Exception ex)
        {
            fileTransferStatus = SftpFileSentStatus.Failed;
        }
        finally
        {
            if (client.State == SftpState.Connected || client.State == SftpState.Ready)
                client.Disconnect(); client.Dispose();
        }
    }
    else fileTransferStatus = SftpFileSentStatus.Inconclusive;
    return fileTransferStatus;
}

Here is the stack trace:

   at Rebex.Net.SftpCore.ThrowOnError(Packet packet, Type expected)
   at Rebex.Net.SftpCore.Open(String path, SftpOpenMode mode, Boolean failOnError)
   at Rebex.Net.Sftp.PutFileInternal(SftpOpenMode mode, Object state, String remotePath, Stream sourceStream, Int64 remoteOffset, Int64 length)
   at Rebex.Net.Sftp.PutFileInternal(SftpOpenMode mode, Object state, String remotePath, String localPath, Int64 remoteOffset, Int64 localOffset, Int64 length)
   at Rebex.Net.Sftp.PutFile(String localPath, String remotePath)
   at InstallationDiagnostics.InstallationTests.SendSftpTestFile(MGAManager mga, String pFileName, String sURI) in C:\Documents and Settings\svasily\My Documents\Visual Studio 2008\Projects\MGA XML Extracts\InstallationDiagnostics\InstallationTests.cs:line 275
Applies to: File Transfer Pack

1 Answer

0 votes
by (148k points)
edited
 
Best answer

This SftpException was thrown as a result of an error reported by the SFTP server. Failure status code and message is all information it provided, which is not very useful. However, the error occured while trying to open/create a file at the SFTP server, so the most likely explanation is that something is wrong with the path (your sURI argument). Please make sure the path is correct and try again.

If you can't find any problem, use Sftp object's LogWriter property to create a communication log (you only have to add one line to your code) and either mail it to us (support@rebex.net) for analysis or edit your question to include it.

by (150 points)
Thank you Lucas, you r right. The lack of information on the exception threw my diligence into the wrong path (u know, a tendency to complicate things) - it was simply the sURI problem. It must include the file name at the end as well, not just the directory. Thanks a lot and have fun on the blog.
...