Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.1k views
in .NET FTP by (540 points)
I am opening a passive FTP connection to a server tha accepts both FTP and SFTP connections. One I run an exists command using the SFTP connection I don't get any exceptions if I run the same code with an FTP connection I'm getting the following exception:

EnterpriseDT.Net.Ftp.FTPException: Unable to determine if file 'test' exists..

Here is the debug log

DEBUG [FTPConnection] 2 Aug 2012 12:37:35.626 : Set LocalDirectory='C:\svn\dev\branches\Product\Solution\TestResults\Framework _2012-08-02 12_37_34_\Out'
DEBUG [SecureFTPConnection] 2 Aug 2012 12:37:35.626 : Set LocalDirectory to C:\svn\dev\branches\Product\Solution\TestResults\Framework _2012-08-02 12_37_34_\Out
INFO [LicenseProperties] 2 Aug 2012 12:37:35.628 : Licence expiry date: 12/31/9999
INFO [LicenseProperties] 2 Aug 2012 12:37:35.628 : Production license
DEBUG [SSLFTPClient] 2 Aug 2012 12:37:35.628 : Connecting to sftp.mercent.com:21
DEBUG [SSLFTPControlSocket] 2 Aug 2012 12:37:35.629 : waitOnShutdownSSL=True
DEBUG [HostNameResolver] 2 Aug 2012 12:37:35.638 : Resolving sftp.mercent.com
DEBUG [HostNameResolver] 2 Aug 2012 12:37:35.642 : Obtained 1 addresses
DEBUG [HostNameResolver] 2 Aug 2012 12:37:35.642 : IP address: 184.72.102.212
DEBUG [HostNameResolver] 2 Aug 2012 12:37:35.642 : sftp.mercent.com resolved to 184.72.102.212
DEBUG [ExFTPControlSocket] 2 Aug 2012 12:37:35.642 : Connecting directly to ftp-server sftp.mercent.com:21
INFO [SSLFTPSocket] 2 Aug 2012 12:37:35.643 : Connecting to 184.72.102.212:21 with timeout 0 ms
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:35.716 : Setting socket timeout=0
INFO [FTPControlSocket] 2 Aug 2012 12:37:35.718 : Command encoding=System.Text.SBCSCodePageEncoding
DEBUG [ExFTPControlSocket] 2 Aug 2012 12:37:35.718 : Created control-socket: SocksContext=, ProxySettings=NoProxy, RemoteHost=sftp.mercent.com, controlPort=21, timeout=0
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:35.720 : StrictReturnCodes=False
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:35.788 : 220-Microsoft FTP Service
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:35.788 : 220 Welcome
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:35.792 : ---> USER Testftp1
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:35.864 : 331 Password required for Testftp1.
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:35.865 : ---> PASS ********
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:35.937 : 230 User logged in.
DEBUG [FTPConnection] 2 Aug 2012 12:37:35.937 : Successfully logged in
DEBUG [ExFTPConnection] 2 Aug 2012 12:37:35.939 : Starting KeepAlive thread with period 30s
INFO [FTPConnection] 2 Aug 2012 12:37:35.939 : Auto FEAT disabled
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:35.940 : ---> TYPE I
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.012 : 200 Type set to I.
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.012 : ---> PWD
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.136 : 257 "/" is current directory.
DEBUG [FTPConnection] 2 Aug 2012 12:37:36.138 : Exists(test)
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.139 : ---> SIZE test
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.212 : 550 Access is denied.
DEBUG [FTPClient] 2 Aug 2012 12:37:36.213 : SIZE not supported
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.213 : ---> MDTM test
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.284 : 550 The specified path is invalid.
DEBUG [FTPClient] 2 Aug 2012 12:37:36.284 : MDTM not supported
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.286 : ---> PORT 172,18,2,120,242,246
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.358 : 200 PORT command successful.
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.358 : ---> RETR test
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.431 : 550 Access is denied.
WARN [FTPClient] 2 Aug 2012 12:37:36.431 : Unable to determine if file 'test' exists.
DEBUG [FTPConnection] 2 Aug 2012 12:37:36.436 : Closing connection (instance=0)
DEBUG [FTPFileFactory] 2 Aug 2012 12:37:36.437 : Defaulting to Unix parsing
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.437 : ---> QUIT
DEBUG [ExFTPConnection] 2 Aug 2012 12:37:36.440 : KeepAlive thread finished.
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.510 : 221 Goodbye.
DEBUG [SecureSocket] 2 Aug 2012 12:37:36.511 : Shutdown(Both)


I've tried both active and passive connections.

Help!
Thanks,
Kathy

7 Answers

0 votes
by (162k points)
The problem here is that the string the server sends back to indicate the file is not found is unexpected. This technique is used because the message number, 550, does not always mean it does not exist.

You can fix this by explicitly adding it:

FTPConnection conn = new FTPConnection();
conn.FileNotFoundMessages.Add("specified path is invalid");
0 votes
by (540 points)
Here's the thing the path is valid and work's through the sftp connection.
0 votes
by (540 points)
I think the problem may actually be

DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.358 : ---> RETR test
DEBUG [FTPControlSocket] 2 Aug 2012 12:37:36.431 : 550 Access is denied.

What I don't understand is I can get to that directory with WinSCP no problem using FTP and SFTP. I can list it and add files. So I don't think it's an error on the server side.
0 votes
by (162k points)
If you are trying to determine if a directory exists, try changing into it.

If you are trying to determine if a file exists, use Exists().
0 votes
by (540 points)
I know the difference between changing directories and checking if a directory or file exists. I am trying to write a program that does both among other things. It's failing on the Exists. I'm testing which is how I know the directory exists, when this runs in production it will need to work. Are you saying that for FTP connections Exists does not work for directories?
0 votes
by (162k points)
Yes, it should be called ExistsFile.
0 votes
by (540 points)
that worked thank you!!!

Kathy

Categories

...