|
Work fine on upload but I can't download a file from server. It said file not found everytime.
|
|
|
|
|
This compiled easily for compact framework and works very well. Thank you.
|
|
|
|
|
In the project this one was inspired by, you had a 'IsConnected' property in the FTP client class. To check if you where connected.
How do I check my connection in this one.
|
|
|
|
|
After using this library for a while, I finally switched to "Alex FTPS Client".
In my opinion "Alex FTPS Client" is easier to use and more stable!
http://ftps.codeplex.com/
|
|
|
|
|
i don't know how the many methods and properties to be used.
FTP ftp = new FTP();<br />
if (textBox3.Text.Trim().Length == 0)<br />
ftp.Connect(textBox1.Text, textBox2.Text, textBox4.Text);<br />
else<br />
ftp.Connect(textBox1.Text, int.Parse(textBox3.Text), textBox2.Text, textBox4.Text);<br />
<br />
List<string> list = new List<string>();<br />
foreach (FTP.Directory dir in ftp.Directories)<br />
{<br />
list.Add(dir.DirectoryName);<br />
}<br />
foreach (FTP.File f in ftp.Files)<br />
{<br />
list.Add(f.FileName);<br />
}
but it retrieved nothing.
pclion
|
|
|
|
|
I try this..
OpenFTP.FTP f = new OpenFTP.FTP();
f.Connect("xxx.xxx.xxx.xxx", "ID", "PW");
f.ChangeDirectory("root");
f.ChangeDirectory("public");
//f.Files.Upload("pippo.txt", "C:\\Tmp\\pippo2.txt");
f.Files.Download("pippo.txt", "C:\\Tmp\\pippo3.txt");
and not work. Why?
P.s.
Upload work correctly.
Regards.
Alex
Alex
|
|
|
|
|
I think i know why several users have bugs with this project. Honestly, i like this lib, but it was designed only for Win FTP Servers. When i tried to ChangeDirectory("test") or something it just threw an exception without any visible reason. So I checked the source code, stepped through it and two main mistakes are in these two methods:
public void Add(string sUnparsedFile)
and
public void Add(string sUnparsedDirectory)
Here the methods try to parse the filesize and the file and directory date (without any exception handling). The problem is that the string does not match the method which extracts the data. Win != Linux.
I can give you my workaround solution for these two methods, but i will try to solve the problems in a better way and post it here.
public void Add(string sUnparsedDirectory)
{
string sDirectoryName = sUnparsedDirectory.Substring(39).Trim().Replace("\r", "");
DateTime dtDirectoryDate;
try
{
dtDirectoryDate = Convert.ToDateTime(sUnparsedDirectory.Substring(0, 8) + " " + sUnparsedDirectory.Substring(10, 7));
}
catch (FormatException)
{
dtDirectoryDate = new DateTime();
}
Add(sDirectoryName, dtDirectoryDate);
}
public void Add(string sUnparsedFile)
{
string sFileName = sUnparsedFile.Substring(39).Trim().Replace("\r","");
long lFileSize;
DateTime dtFileDate;
try
{
lFileSize = long.Parse(sUnparsedFile.Substring(17, 21).Trim());
dtFileDate = Convert.ToDateTime(sUnparsedFile.Substring(0, 8) + " " + sUnparsedFile.Substring(10, 7));
}
catch (FormatException)
{
lFileSize = 0;
dtFileDate = new DateTime();
}
Add(sFileName, lFileSize, dtFileDate);
}
greez
|
|
|
|
|
My solution to this problem:
private static Match GetMatchingRegex(string line)
{
Regex rx;
Match m;
for (int i = 0; i <= _ParseFormats.Length - 1; i++)
{
rx = new Regex(_ParseFormats[i]);
m = rx.Match(line);
if (m.Success)
{
return m;
}
}
return null;
}
#region "Regular expressions for parsing LIST results"
private static string[] _ParseFormats = new string[] {
"(?<dir>[\\-d])(?<permission>([\\-r][\\-w][\\-xs]){3})\\s+\\d+\\s+\\w+\\s+\\w+\\s+(?<size>\\d+)\\s+(?<timestamp>\\w+\\s+\\d+\\s+\\d{4})\\s+(?<name>.+)",
"(?<dir>[\\-d])(?<permission>([\\-r][\\-w][\\-xs]){3})\\s+\\d+\\s+\\d+\\s+(?<size>\\d+)\\s+(?<timestamp>\\w+\\s+\\d+\\s+\\d{4})\\s+(?<name>.+)",
"(?<dir>[\\-d])(?<permission>([\\-r][\\-w][\\-xs]){3})\\s+\\d+\\s+\\d+\\s+(?<size>\\d+)\\s+(?<timestamp>\\w+\\s+\\d+\\s+\\d{1,2}:\\d{2})\\s+(?<name>.+)",
"(?<dir>[\\-d])(?<permission>([\\-r][\\-w][\\-xs]){3})\\s+\\d+\\s+\\w+\\s+\\w+\\s+(?<size>\\d+)\\s+(?<timestamp>\\w+\\s+\\d+\\s+\\d{1,2}:\\d{2})\\s+(?<name>.+)",
"(?<dir>[\\-d])(?<permission>([\\-r][\\-w][\\-xs]){3})(\\s+)(?<size>(\\d+))(\\s+)(?<ctbit>(\\w+\\s\\w+))(\\s+)(?<size2>(\\d+))\\s+(?<timestamp>\\w+\\s+\\d+\\s+\\d{2}:\\d{2})\\s+(?<name>.+)",
"(?<timestamp>\\d{2}\\-\\d{2}\\-\\d{2}\\s+\\d{2}:\\d{2}[Aa|Pp][mM])\\s+(?<dir>\\<\\w+\\>){0,1}(?<size>\\d+){0,1}\\s+(?<name>.+)",
"(?<dir>[\\-d])(?<permission>([\\-r][\\-w][\\-xs]){3})\\s+\\d+\\s+\\(\\w+\\)\\s+\\(\\w+\\)\\s+(?<size>\\d+)\\s+(?<timestamp>\\w+\\s+\\d+\\s+\\d{1,2}:\\d{2})\\s+(?<name>.+)"};
#endregion
public void Add(string sUnparsedDirectory)
{
sUnparsedDirectory = sUnparsedDirectory.Replace("\r", string.Empty);
string sDirectoryName = string.Empty;
DateTime dtDirectoryDate;
Match m = GetMatchingRegex(sUnparsedDirectory);
if (m == null)
{
throw (new ApplicationException("Unable to parse line: " + sUnparsedDirectory));
}
else
{
sDirectoryName = m.Groups["name"].Value;
if (DateTime.TryParse(m.Groups["timestamp"].Value, out dtDirectoryDate) == false)
{
dtDirectoryDate = DateTime.MinValue;
}
}
Add(sDirectoryName, dtDirectoryDate);
}
public void Add(string sUnparsedFile)
{
sUnparsedFile = sUnparsedFile.Replace("\r", string.Empty);
string sFileName = string.Empty;
DateTime dtFileDate;
long lFileSize = 0;
Match m = GetMatchingRegex(sUnparsedFile);
if (m == null)
{
throw (new ApplicationException("Unable to parse line: " + sUnparsedFile));
}
else
{
sFileName = m.Groups["name"].Value;
string sFileSize = m.Groups["size"].Value;
long.TryParse(sFileSize, out lFileSize);
if (DateTime.TryParse(m.Groups["timestamp"].Value, out dtFileDate) == false)
{
dtFileDate = DateTime.MinValue;
}
}
Add(sFileName, lFileSize, dtFileDate);
}
Works pretty good so far
|
|
|
|
|
I have tried with 2 different servers.
It connects but then says that there are 0 files and when I try to download a file it says it could not be found.
namespace NeoUpdate.Core
{
public class UpdateItSelf
{
public void CheckForUpdate()
{
OpenFTP.FTP f = new OpenFTP.FTP();
f.Connect("xxxxxx", "xxxxx", "xxxxx");
string dir = f.Directories.GetWorkingDirectory();
string fileNames;
f.Files.RebuildFileList();
for( int i=0; i < f.Files.Count; ++i){
fileNames = f.Files[i].FileName;
}
f.Files.Download("n.txt");
|
|
|
|
|
ftplib had support to Active Mode. How do I use Active Mode in your OpenFTP class ?
|
|
|
|
|
I'm really not sure, the ftplib was a basic class for accessing an FTP, I simply wrote a wrapper around it with methods and properties to make it easier to use. The underlying code didn't really change so if the functionality was there before it should still be there, or at least be accessible.
Jmers
|
|
|
|
|
Ok, I put the internal class FTPPlumbing to public, and is downloading the files. The problem now is that all files are empty. I taked a look at the Download method and I can not see the code of receiving bytes from the socket.
public void Download(string sRemoteFilename, string sLocalFilename, bool bResume)
{
if (FTPPlumbing.IsConnected)
{
FTPPlumbing.SetBinaryMode(true);
SelectedFileSize = this[sRemoteFilename].FileSize;
TotalBytes = 0;
PercentComplete = 0;
#region Setup File
if (bResume && System.IO.File.Exists(sLocalFilename))
{
#region Setup File to Resume
try
{
FTPPlumbing.file = new FileStream(sLocalFilename, FileMode.Open);
}
catch (Exception e)
{
FTPPlumbing.file = null;
throw e;
}
FTPPlumbing.SendCommand("REST " + FTPPlumbing.file.Length);
if (FTPPlumbing.ResponseCode != FTPPlumbing.FTPResponseCode.FileActionPended)
{
throw new Exception(FTPPlumbing.ResponseString);
}
FTPPlumbing.file.Seek(FTPPlumbing.file.Length, SeekOrigin.Begin);
TotalBytes = FTPPlumbing.file.Length;
#endregion Setup File to Resume
}
else
{
#region Setup File for Initial Download
try
{
FTPPlumbing.file = new FileStream(sLocalFilename, FileMode.Create);
}
catch (Exception e)
{
FTPPlumbing.file = null;
throw e;
}
#endregion Setup File for Initial Download
}
#endregion Setup File
#region Connect Socket
FTPPlumbing.OpenDataSocket();
FTPPlumbing.SendCommand("RETR " + sRemoteFilename);
switch (FTPPlumbing.ResponseCode)
{
case FTPPlumbing.FTPResponseCode.DataConnectionAlreadyOpen:
case FTPPlumbing.FTPResponseCode.FileStatusOK:
break;
default:
FTPPlumbing.file.Close();
FTPPlumbing.file = null;
throw new Exception(FTPPlumbing.ResponseString);
}
FTPPlumbing.ConnectDataSocket();
#endregion Connect Socket
}
else
{
throw new Exception("FTP Not Connected - Download Cannot Begin");
}
}
|
|
|
|
|
I just found myself needing Active mode. Might I suggest that you add the following into the FTP class:
public int Port
{
get { return FTPPlumbing.Port; }
}
// DJC - Expose the passive flag to apps
public bool PassiveMode
{
get { return FTPPlumbing.PassiveMode; }
set { FTPPlumbing.PassiveMode = value; }
}
public long TotalBytes
{
get { return lTotalBytes; }
set { lTotalBytes = value; }
}
|
|
|
|
|
When I try to connect to an FTP Server (ftp://ftp.ibiblio.org/) using this library, I get the following error:
System.Net.Sockets.SocketException was unhandled
ErrorCode=11004
Message="The requested name is valid, but no data of the requested type was found"
NativeErrorCode=11004
Source="System"
I removed the rest of the Message.
Here is the code that threw the exception:
f.Connect("ftp://ftp.ibiblio.org", "Anon", "")
If you would like to see the entire error message, I will email it to you.
My email is ztgreve@gmail.com
This error does not make much sense to me.
Ztgreve
|
|
|
|
|
Did you try the address part without the "ftp://"? When I connect using it, I only use the domain name portion.
Jmers
|
|
|
|
|
hello and thanks for the code !
Can anyone explain me how to upload folders ?
thanks
|
|
|
|
|
Hello, can you post this useful dll for CF 3.5?
Thanks
|
|
|
|
|
try<br />
{<br />
main_sock.Connect(main_ipEndPoint);<br />
}<br />
catch (Exception ex)<br />
{<br />
throw new Exception(ex.Message);<br />
}
life is study!!!
|
|
|
|
|
I second that LOL.
|
|
|
|
|
When I try to call Files.Upload(remoteFileName, localFileName), I get this:
startIndex cannot be larger than length of string. Parameter name: startIndex
What's up with that? I'm gonna try to finger it out, but I could use some rather immediate urgent help.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Friday, January 9, 2009 5:38 AM
|
|
|
|
|
Hi,
I am using openFTP dll in windows service develope in vs 2008.
This service will get all files from local directory and upload it to two different FTP server.
I am opening first ftp server using
FTP() ObjFTP =null;
ObjFTP = new FTP();
ObjFTP.Connect(_sRemoteHost, _iPort, _sRemoteUser, _sRemotePassword);
and once upload done. I am closing this instance by using
try
{
if (ObjFTP != null)
{
ObjFTP.Disconnect();
}
}
catch (Exception ex)
{
ObjFTP = null;
}
But getting an error saying "Connection forcefully disconnected"
Then I am again opening the instance for second FTP server as my requirment to upload these file to second FTP server also.
ObjFTP = new FTP();
ObjFTP.Connect(_sRemoteHost, _iPort, _sRemoteUser, _sRemotePassword);
But I am not able to upload it to second FTP Server.
Is this possible to upload files to two different FTP servers in a process
Please help.............
|
|
|
|
|
Hi, I don't know why I'm getting this error after clicking the button..
This is my code below just to upload a file to my web server.
private void button1_Click(object sender, EventArgs e)
{
string sFileName = "c:\\hello.txt";
OpenFTP.FTP f = new OpenFTP.FTP();
f.Connect("", "", "");
f.ChangeDirectory("");
f.Files.Upload(Path.GetFileName(sFileName), Path.GetFileName(sFileName));
StringBuilder sbTxtMessage = new StringBuilder();
while (!f.Files.UploadComplete)
{
sbTxtMessage.Append("Uploading: TotalBytes: " + f.Files.TotalBytes.ToString() + ", :PercentComplete: " + f.Files.PercentComplete.ToString());
txtMessage.Text = sbTxtMessage.ToString();
}
sbTxtMessage.Append("Upload Complete: TotalBytes: " + f.Files.TotalBytes.ToString() + ", : PercentComplete: " + f.Files.PercentComplete.ToString());
f.Disconnect();
f = null;
}
Warning 1 'System.Net.Dns.GetHostByName(string)' is obsolete: 'GetHostByName is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202' E:\Practice\Csharp_mobile\FTPClient\FTPClient\ftp.cs 470 38 FTPClient
Warning 2 'System.Net.Dns.GetHostByName(string)' is obsolete: 'GetHostByName is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202' E:\Practice\Csharp_mobile\FTPClient\FTPClient\ftp.cs 599 40 FTPClient
Warning 3 Unreachable code detected E:\Practice\Csharp_mobile\FTPClient\FTPClient\ftp.cs 1186 10 FTPClient
Warning 4 Unreachable code detected E:\Practice\Csharp_mobile\FTPClient\FTPClient\ftp.cs 1256 10 FTPClient
I'm sure the ftp user information I input in the ftp.cs f.connect(...) is correct because I was able to make it work in FtpLib by J.P. Trosclair's version.
Any ideas why I received this error "A socket operation encountered a dead network" ?
I'm new to C# so please help. Thanks.
|
|
|
|
|
I'm using it to download files. It is a good tool.
thanks
|
|
|
|
|
the upload was success but return this error.
here the code:
string sFileName ="D:\\web_development\\file.xml";
OpenFTP.FTP f = new OpenFTP.FTP();
//f.Connect("xxx.xxx.xx.xx", "user", "password");
f.Files.Upload(Path.GetFileName(sFileName),sFileName);
|
|
|
|
|
Hello
If you search a comfortable and reusable FTP client,
-- which is running on .NET Framework 1.1 or higher,
-- which can automatically put together splitted files on the server,
-- which allows to download only a part of a file on the server,
-- which allows to resume any broken download,
-- which automatically starts a separate thread,
-- which can be aborted any time from your main thread,
-- which supports UTF8 encoded filenames,
-- which has a built-in download scheduler,
-- which has a built-in bandwidth control,
-- which has a built-in preview function for the download of movies,
-- which automatically reconnects the server after an error has occurred,
-- which displays download progress in percent and in bytes and the remaining time,
-- which writes a detailed logging for all operations it does,
-- which is based on Wininet.dll and has one workaround for each of the 4 known Wininet.dll bugs,
-- which is very well tested and bug-free,
-- which is written by a very experienced programmer and has a very clean and well documented sourcecode,
then have a look at this project:
ElmueSoft Partial FTP Downloader[^]
Elmü
|
|
|
|
|