Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.8k views
in .NET FTP by (200 points)
Hi,

I am trying to get multiple files from a server using FtpClient.Get(theDestination, theSource) and place them on my hard drive. I tried to loop through particular files on the server and kept getting an error;

System.IO.IOException: The process cannot access the file "c:\logTest\sample04.txt" because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileInfo.Delete()
at EnterpriseDT.Net.Ftp.FTPClient.GetASCII(String localPath, String remoteFil
e)
at EnterpriseDT.Net.Ftp.FTPClient.Get(String localPath, String remoteFile)
at ftpTest.Class1.Main(String[] args) in c:\csharp_snippets\ftpcsharp\test01\
ftptest\class1.cs:line 52

why am i getting this error? Below are pieces of code i used....
...
ftp = new FTPClient(host);
ftp.Login(user, password);

ftp.ConnectMode = FTPConnectMode.PASV;
ftp.TransferType = FTPTransferType.ASCII;

//...
for(i = 0; i < 25; i++)
{
ftp.Get(@"c:\logTest\"+destFile[i], @"/myServer/"+sourceFile[i]);
ftp.TransferCompleteEx += new TransferHandler(ftp_TransferCompleteEx);
}

//...

private static void ftp_TransferCompleteEx(object sender, TransferEventArgs e)
{
Console.WriteLine("--------------------------------");
Console.WriteLine("File Transfer Complete");
Console.WriteLine("--------------------------------\n\n");
}

it works for some of the iterations, but i get the error around the 4th iteration.

cheers,

5 Answers

0 votes
by (162k points)
Please post a chunk of the log file.
0 votes
by (200 points)
hi again, this is my code without the declarations for host, user and password. dont have a log file

try
{
ftp = new FTPClient(host);

ftp.Login(user, password);

ftp.ConnectMode = FTPConnectMode.PASV;
ftp.TransferType = FTPTransferType.ASCII;

//these are just here to test multiple file transfers

string[] files = ftp.Dir("/TestSvr/", true%******");
ftp.Quit();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}


}

private static void ftp_TransferComplete(object sender, EventArgs e)
{
Console.Write("Transfer\n\n", e.ToString());
Console.WriteLine("----------------------------------------------------------------------------------");
}


************************************** the output **************

--------------------------------
File Transfer Complete
--------------------------------


--------------------------------
File Transfer Complete
--------------------------------


--------------------------------
File Transfer Complete
--------------------------------


System.IO.IOException: The process cannot access the file "c:\logTest\sample04.t
xt" because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileInfo.Delete()
at EnterpriseDT.Net.Ftp.FTPClient.GetASCII(String localPath, String remoteFil
e)
at EnterpriseDT.Net.Ftp.FTPClient.Get(String localPath, String remoteFile)
at ftpTest.Class1.Main(String[] args) in c:\csharp_snippets\ftpcsharp\test01\
ftptest\class1.cs:line 49
0 votes
by (162k points)
Look at the Dev Guide for info on enabling logging.

An error is occuring, and the secondary problem you are seeing is a failure to delete the partial file that has been downloaded. We need the log file to determine what is happening.
0 votes
by (200 points)
Hello,

After each FTPClient.Get(string, string) function call, i added CommandSent & ReplyReceived (shown below)


ftp.Get(@"c:\logTest\sample01.txt", "/sunone/sws60_sp5/https-altx/logs/errors.20060601.gz");
ftp.CommandSent+=new FTPMessageHandler(ftp_CommandSent);
ftp.ReplyReceived+= new FTPMessageHandler(ftp_ReplyReceived);

The definitions of ftp_CommandSent & ftp_ReplyReceived follow:

private static void ftp_CommandSent(object sender, FTPMessageEventArgs e)
{
Console.WriteLine("ftp_CommandSent: "+e.ToString());
}

private static void ftp_ReplyReceived(object sender, FTPMessageEventArgs e)
{
Console.WriteLine("ftp_ReplyReceived: "+e.ToString());
}

This is the output i get


ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_CommandSent: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
ftp_ReplyReceived: EnterpriseDT.Net.Ftp.FTPMessageEventArgs
System.IO.IOException: The process cannot access the file "c:\logTest\sample04.t
xt" because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileInfo.Delete()
at EnterpriseDT.Net.Ftp.FTPClient.GetASCII(String localPath, String remoteFil
e)
at EnterpriseDT.Net.Ftp.FTPClient.Get(String localPath, String remoteFile)
at ftpTest.Class1.Main(String[] args) in c:\csharp_snippets\ftpcsharp\test01\
ftptest\class1.cs:line 53

---------------------------------------------
what could i be doing wrong?
0 votes
by (162k points)
sorry, we need the log file - see the Dev Guide.

Categories

...