Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.2k views
in .NET FTP by
OK, so I've been trying to get the edtFTPnet Free library to work in a windows service application, and unfortunately haven't had much luck with it so far. I'm hoping that someone here can point me in the right direction for figuring out what the problem is. I'm trying to upload a single zip file (binary I'm pretty sure, right?) into a directory on an IIS 6 FTP server. Here is the code that I am using to attempt to upload the file:

/// <summary>
/// Uploads the given backup file to the FTP host
/// </summary>
/// <param name="filepath">The backup file to upload</param>
public void Upload( string filepath )
{
    try
    {
        string remoteFileName = setRemoteFileName( filepath );
        _ftpConnection = new FTPConnection();
        _ftpConnection.ServerAddress = _ftpConfig.Host;
        _ftpConnection.UserName = _ftpConfig.Username;
        _ftpConnection.Password = _ftpConfig.Password;
        _ftpConnection.ConnectMode = FTPConnectMode.ACTIVE;
        _ftpConnection.TransferType = FTPTransferType.BINARY;
        _ftpConnection.Connect();
        _ftpConnection.Login();
        _ftpConnection.ChangeWorkingDirectory( _ftpConfig.FolderPath );
        _ftpConnection.UploadFile( filepath, remoteFileName );
    }
    catch( Exception ex )
    {
        Log.AddError( "Error uploading backup file " + filepath + " to FTP server.", Priority.High, TraceEventType.Error, Category.Error, EventID.FTPUpload, ex );
    }
    finally
    {
        if( _ftpConnection != null )
        {
            if( _ftpConnection.IsConnected )
            {
                _ftpConnection.Close();
            }
            _ftpConnection.Dispose();
        }
    }


And here is the error that I'm getting:

EnterpriseDT.Net.Ftp.FTPException: BackBurner.200701071734.zip: Access is denied. (code=550)
at EnterpriseDT.Net.Ftp.FTPControlSocket.ValidateReply(FTPReply reply, String[] expectedReplyCodes)
at EnterpriseDT.Net.Ftp.FTPClient.InitPut(String remoteFile, Boolean append)
at EnterpriseDT.Net.Ftp.FTPClient.PutBinary(Stream srcStream, String remoteFile, Boolean append)
at EnterpriseDT.Net.Ftp.FTPClient.PutBinary(String localPath, String remoteFile, Boolean append)
at EnterpriseDT.Net.Ftp.FTPClient.Put(String localPath, String remoteFile, Boolean append)
at EnterpriseDT.Net.Ftp.FTPConnection.UploadFile(String localPath, String remoteFile, Boolean append)
at EnterpriseDT.Net.Ftp.FTPConnection.UploadFile(String localPath, String remoteFile)
at BackBurner.Service.Ftp.Uploader.Upload(String filepath) in C:\@ryexley\Visual Studio 2005\Projects\BackBurner\BackBurner.Service\Ftp\Uploader.cs:line 67

Also, just FYI...the Log.AddError call is from my logger, not the logger included with the edtFTPnet library. If anyone has any ideas of what I might be doing wrong, I would be very grateful. Thanks in advance.

4 Answers

0 votes
by (162k points)
Have a look at the user you are running the service as ... perhaps it doesn't have permission to read the local file?
0 votes
by
The service actually created the file, so it certainly has access to it. At first I was actually thinking that I was getting Access Denied because the file was still locked by the service after creating it, but I've gone back and double-checked to make sure that the file is in fact accessible and no longer locked by the service. So I'm pretty sure its an issue on the server side, but I'm not sure what the problem is. I do know for sure that the user that I'm logging into the server with has write permissions. There must be something else that I'm missing.
0 votes
by (162k points)
Yes, it is actually a server error so the server mustn't have permission to write that file in the current directory.
0 votes
by
Hhmmm....interesting. So, I tried removing the call to ChangeWorkingDirectory, and just uploading to the root folder, and everything worked fine. So, it seemed that there is some sort of problem with permissions on the directory that I changed to and uploading/creating a file there.

So, to test the theory, I opened up SmartFTP, logged in as the same user, switched to the directory that I was attempting to switch to programatically, and manually uploaded the file. The transfer went through just fine. So, it seems that I do in fact have the privileges to upload the file to the directory I was trying to, and I couldn't figure out what the problem was. But, I went and looked at the log generated by SmartFTP, and found the following details in the log:

[00:58:43] CWD /ryexley/Users
[00:58:43] 250 CWD command successful.
[00:58:43] PWD
[00:58:43] 257 "/ryexley/Users" is current directory.
[00:58:43] PORT 192,168,1,151,5,228
[00:58:43] 200 PORT command successful.
[00:58:43] LIST -aL
[00:58:43] 150 Opening ASCII mode data connection for /bin/ls.
[00:58:43] 96 bytes transferred. (N/A/s) (0 ms)
[00:58:43] 226 Transfer complete.
[00:58:45] CWD /ryexley/Users/ryexley
[00:58:45] 250 CWD command successful.
[00:58:45] PWD
[00:58:45] 257 "/ryexley/Users/ryexley" is current directory.
[00:58:45] PORT 192,168,1,151,5,230
[00:58:45] 200 PORT command successful.
[00:58:45] LIST -aL
[00:58:45] 150 Opening ASCII mode data connection for /bin/ls.
[00:58:45] 343 bytes transferred. (N/A/s) (0 ms)
[00:58:45] 226 Transfer complete.
[00:58:46] CWD /ryexley/Users/ryexley/Backup
[00:58:47] 250 CWD command successful.
[00:58:47] PWD
[00:58:47] 257 "/ryexley/Users/ryexley/Backup" is current directory.
[00:58:47] PORT 192,168,1,151,5,232
[00:58:47] 200 PORT command successful.
[00:58:47] LIST -aL
[00:58:47] 150 Opening ASCII mode data connection for /bin/ls.
[00:58:47] 0 bytes transferred. (N/A/s) (0 ms)
[00:58:47] 226 Transfer complete.
[00:59:12] Remote file exist check: "BackBurner.200701090056.zip".
[00:59:12] TYPE I
[00:59:12] 200 Type set to I.
[00:59:12] SIZE BackBurner.200701090056.zip
[00:59:12] 550 BackBurner.200701090056.zip: The system cannot find the file specified.
[00:59:12] File size check (SIZE) failed. File not found or permission denied.
[00:59:12] PORT 192,168,1,151,5,234
[00:59:12] 200 PORT command successful.
[00:59:12] STOR BackBurner.200701090056.zip
[00:59:12] 150 Opening BINARY mode data connection for BackBurner.200701090056.zip.
[00:59:14] 1881339 bytes transferred. (1.18 MB/s) (00:00:01)
[00:59:14] 226 Transfer complete.
[00:59:14] MDTM 20070109055645 BackBurner.200701090056.zip
[00:59:14] 550 20070109055645 BackBurner.200701090056.zip: The system cannot find the file specified.
[00:59:14] SIZE BackBurner.200701090056.zip
[00:59:14] 213 1881339
[00:59:14] Transfer successful.
[00:59:14] TYPE A
[00:59:14] 200 Type set to A.
[00:59:14] PORT 192,168,1,151,5,236
[00:59:14] 200 PORT command successful.
[00:59:14] LIST -aL
[00:59:14] 150 Opening ASCII mode data connection for /bin/ls.
[00:59:14] 68 bytes transferred. (N/A/s) (0 ms)
[00:59:14] 226 Transfer complete.

The entry that intrigued me the most was:
[00:59:14] 550 20070109055645 BackBurner.200701090056.zip: The system cannot find the file specified.

Because that was the same error that I was getting when attempting to upload with edtFTPnet programatically. So...I'm not sure what the problem is. SmartFTP seems to work fine, but it does still get the same error. Do I need to make my code a little bit more robust to handle hiccups like that or what? I unfortunately don't really know enough about FTP to know what's really going wrong there, but something is obviously weird. Anybody got any ideas of what I can do?

Categories

...