Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.7k views
in .NET FTP by (160 points)
Hi all, I have a strange problem here. I am trying to implement a very basic file get(). Everything looks fine but I don't seem to be actually getting the file on the web application's harddisk.

Here is a section of the C# .NET code:


FTPClient ftp = new FTPClient();
ftp.RemoteHost = FTPHostName;
ftp.Connect();

ftp.Login("username", "password");
ftp.CommandSent += new FTPMessageHandler(LogCommand);
ftp.ReplyReceived += new FTPMessageHandler(LogReply);

ftp.TransferType = FTPTransferType.ASCII;

ftp.ChDir(FTPDirectory);
ftp.CommandSent += new FTPMessageHandler(LogCommand);
ftp.ReplyReceived += new FTPMessageHandler(LogReply);

ftp.Get(DataFileName);
ftp.CommandSent += new FTPMessageHandler(LogCommand);
ftp.ReplyReceived += new FTPMessageHandler(LogReply);
ftp.TransferStarted += new EventHandler(LogTransferStarted);
ftp.TransferComplete += new EventHandler(LogTransferComplete);

ftp.Quit(); //disconnect
ftp.CommandSent += new FTPMessageHandler(LogCommand);
ftp.ReplyReceived += new FTPMessageHandler(LogReply);


for quick development and testing, I have LogCommand and LogReply methods to do simple trace.write

internal void LogCommand(object src, FTPMessageEventArgs e)
{
Trace.Write("LogCommand", e.Message);
}
internal void LogReply(object src, FTPMessageEventArgs e)
{
Trace.Write("LogReply", e.Message);
}

everything looks fine in the trace page. The most important trace lines are:

LogCommand ---> RETR myFile.txt 0.075365 0.000072
LogReply 150 Opening data connection for myFile.txt (181 bytes). 0.076532 0.000033
LogReply 226 Transfer complete. 0.089246 0.000303
LogCommand ---> QUIT 0.089897 0.000651
LogReply 221 Goodbye. 0.091646 0.001682

looks all well and good. But the problem is I can't find the download file anywhere on the harddrive of the web application.

I know the default lcd is the current directory of the application and cannot be changed. I am not sure what the current directory is so I search the whole HD for it (unless it is on another disk/petition?)

Does anyone know what I am doing wrong and what should I do? Thanks!

5 Answers

0 votes
by (161k points)
You need to use

public virtual void Get(string,string);

Hi all, I have a strange problem here. I am trying to implement a very basic file get(). Everything looks fine but I don't seem to be actually getting the file on the web application's harddisk.
0 votes
by (160 points)
Thank you! I've made some progress with your help, but stuck again now on a new problem :(

I get

Access to the path "D:\temp" is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path "D:\temp" is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:


Line 155: ftp.ReplyReceived += new FTPMessageHandler(LogReply);
Line 156:
Line 157: ftp.Get(FTPLocalDirectory, DataFileName);
Line 158: ftp.CommandSent += new FTPMessageHandler(LogCommand);
Line 159: ftp.ReplyReceived += new FTPMessageHandler(LogReply);



I've given myComputerName\ASPNET access rights to the directory I am downloading the file to, even tried giving it "full control" to the whole D: drive and it's still giving this message.

Is there something else I need to set, in IIS or something?
0 votes
by
I can't help, but I'm getting the exact same error message....
0 votes
by
Found another post with the answer..

It's NOT ftp.get(folder,file)

It's .... ftp.get(Folder + file, file)

That works just fine...

Bill
0 votes
by
Hey Bill, it is exactly as you say, thanks a lot!!!

Categories

...