Home Forums .NET libraries Xceed SFTP/FTP for .NET GetFolderContents returns FtpIOException when file does not exist, then stops any transfers that occur afterwards

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21216 |

    Hello!  I have a particular need to upload files, but check to make sure the file does not exist before transferring (I allow the user to decide whether to overwrite or not).  So basically I’m doing something like:

    http://ftp.Connect(…)
    http://ftp.Login(…)
    if (!overwrite) {
        FtpItemInfoList items = http://ftp.GetFolderContents(“file.txt”);
        if (items.Count == 0) {
            http://ftp.SendFile(stream, fileToSave.Key);
        }
    } else {
        http://ftp.SendFile(stream, fileToSave.Key);
    }

    If overwrite is false, and file.txt does not exist, I get an FtpIOException “An I/O error occurred while accepting the FTP server’s data connection.” and an InnerException of “No connection could be made because the target machine actively refused it 192.168.x.x:4781”  I can live with that.

    When I try to send the file (the code above does not depict this, but the actual code I wrote is supposed to send the file because if the remote file does not exist the overwrite flag doesn’t mean anything), I get another exception – this time FtpInternalError “An unexpected error occurred while connecting to the FTP server.” with the InnerException of “The BeginRead method cannot be called when another read operation is pending.”

     What am I doing wrong?  Or is GetFolderContents not working correctly?

     Thanks a bunch.  I’ve gotten my whole client working with this one exception, this library is fantastic!

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by JJ (had 4929 views)

    User (Old forums)
    Member
    Post count: 23064

    Are you using a secure connection?  Are you using AsyncFtpClient?  Is the local file read protected?  Being edited?

    Can you provide the complete stack trace, along the TraceWriter output?

    e.g.:

      FtpClient.TraceWriter = new StreamWriter( @”D:\ftp.log”, true );

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by André (had 2422 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the follow-up, I guess your email subscription feature isn’t working right because I never got notified.  Anyway, I ended up getting around the issue, I think it might have been because I was opening a new connection when checking if the file existed while I already had an existing connection ready to send the file.  I ended up connecting once and passing the connection to the method that checks if the file exists.

     At any rate, it’s working now…but just to answer your questions anyway:

    •  yes, it was using FTPS
    • no, I was not using AsyncFtpClient
    • no, the local file was read/write and was not being edited

    Thanks again for your help!

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by JJ (had 2042 views)

    User (Old forums)
    Member
    Post count: 23064

    Guess I spoke to soon, because this issue just resurfaced now.

    StackTrace:
       at Xceed.Ftp.Engine.FtpCommandSequence.EndExecute(IAsyncResult asyncResult)
       at Xceed.Ftp.FtpClient.DoExecuteCommand(FtpCommandChannel commandChannel, BaseFtpCommand command)
       at Xceed.Ftp.FtpClient.DoSendFile(FtpCommandChannel commandChannel, SendFileFtpCommandSequence sequence)
       at Xceed.Ftp.FtpClient.SendFile(Stream source, String remoteFilename, Boolean append)
       at Xceed.Ftp.FtpClient.SendFile(Stream source, String remoteFilename)
       at [my calling namespace]

     Code snippet:

                        ftp = new FtpClient();
                        http://ftp.UseRemoteAddress = true;
                        http://ftp.CertificateReceived += new CertificateReceivedEventHandler(certificate_received);
                        http://ftp.Connect(this.ServerName, this.AlternatePort, AuthenticationMethod.Tls, VerificationFlags.None, null);
                        http://ftp.Login(this.UserName, this.Password);
                        if (!String.IsNullOrEmpty(this.SubFolder)) {
                            http://ftp.ChangeCurrentFolder(this.SubFolder);
                        }
                        FtpItemInfoList items = http://ftp.GetFolderContents(name); <- triggers FtpIOException “An I/O error occurred while accepting the FTP server’s data connection., inner exception SocketException, message “No connection could be made because the target machine actively refused it 192.168.0.161:2955”

                        …
                        http://ftp.SendFile(stream, fileName); <- triggers FtpInternalException “An unexpected error occurred while connecting to the FTP server., inner exception NotSupportedException, message “The BeginRead method cannot be called when another read operation is pending.”

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by JJ (had 2007 views)

    User (Old forums)
    Member
    Post count: 23064

    And the TraceWriter output:

    > TYPE A
    < 200 Type set to A
    > PASV
    < 227 Entering Passive Mode (192,168,0,161,11,25)
    > LIST hi.txt
    Disconnected from 192.168.0.161:990 on 5/29/2009 @ 3:34:32 PM

    From the FileZilla server log:

    (000008) 5/29/2009 15:34:30 PM – [username] (192.168.0.161)> LIST hi.txt
    (000008) 5/29/2009 15:34:30 PM – [username] (192.168.0.161)> 550 Directory not found.
    (000008) 5/29/2009 15:34:32 PM – [username](192.168.0.161)> disconnected.

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by JJ (had 1994 views)

    User (Old forums)
    Member
    Post count: 23064

    Maybe I just needed a fresh new day to look at this…the problem was occurring because I was not looking for a wildcard or all, I was looking for a specific file.  Now I retrieve all files, and loop through until I find (or don’t find) the one I am looking for, which is working fine.

     

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by JJ (had 3517 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.