|
Hi
How do you change directory when uploading without using the backslashes as in the documentation?
so for example : f.ChangeDirectory("api.hoseasons.co.uk/tradedoubler");
Throws an exception about datetime when slashes are used.
Regards
Danny
|
|
|
|
|
My guess is its looking for a directory named "api.hoseasons.co.uk/tradedoubler", instead of navigating into api.hoseasons.co.uk, and then subsequently into tradedoubler.
The obvious work around would be to issue two ChangeDirectory commands. If I recall correctly the previous version of this control didn't handle that sort of directory navigation and since what I was doing served my needs I didn't see to extend it in that regard.
It would not be difficult though to create a "ChangeDirectories" method, have it parse the "/" out, call ChangeDirectory, Re-build the directory list and do it again for each parsed directory.
Jmers
|
|
|
|
|
Hi,
first of all, thanks for your last reply jmers.
Now, I would like to download all the files in some directory on my FTP server.
I tried to do that with "FTP.fileinfo" and then foreach file name do the download, but I got an error says something wrong with the parameter "line".
So I'll realy appreciate it if you could help me.
Thanks, Idan.
|
|
|
|
|
Hi Idan,
You're welcome. I can tell you how to do what you need to do, I'm not quite sure what you are doing to generate your error but I can't find anything labeled "fileinfo" in the code.
Essentially, to download all files in a directory, you could connect to your FTP server, change to the specified directory, then loop through the files collection downloading each file. Here's how the code would look (note the while loop w/the console.writeline would only be useful in a console app, its here for demonstration purposes):
OpenFTP.FTP f = new OpenFTP.FTP();
f.Connect("127.0.0.1", "username_here", "password_here");
f.ChangeDirectory("somedirectory");
for(int i = 0; i <f.files.count; i++)
{
="" f.files.download(f.files[i].filename,="" @"localpath="" "="" +="" path.getfilename(f.files[i].filename));
="" while="" (!f.files.downloadcomplete)
="" {
="" console.writeline("downloading:="" totalbytes:="" f.files.totalbytes.tostring()="" ",="" :="" percentcomplete:="" f.files.percentcomplete.tostring());
="" }
}
hope="" the="" helps...=""
<div="" class="ForumSig">Jmers
|
|
|
|
|
I don't know why, but it downloads only the first file.
I tried to change your "for" statement to:
for (int i = 0; i < f.Files.Count; i++)
because you wrote an invalid statement (you forgot the ")" and to do something with the last "i").
Thanks for your help.
|
|
|
|
|
Oops yeh.. the for loop was incorrect. As far as I know it should re-build the directories collection and file collection on change of directory, you can of course confirm that as I am not w/o error.
Jmers
|
|
|
|
|
OpenFTP.FTP f = new OpenFTP.FTP();
f.Connect("server", "username", "password");
f.ChangeDirectory("");
// Console.Write("{0}", f.Files.Count);
for(int i = 0; i < f.Files.Count; i++)
{
f.Files.Download(f.Files[i].FileName, "C:\\Test\\" + f.Files[i].FileName);
while (!f.Files.DownloadComplete)
{
Console.WriteLine("Downloading: TotalBytes: " + f.Files.TotalBytes.ToString() + ", : PercentComplete: " + f.Files.PercentComplete.ToString());
}
}
Here is my code.
Right now it's downloading only the first file.
There is some way to do the download with foreach statement?
Something like
:
foreach (file in GetFiles)
{
file.download;
}
Thanks.
|
|
|
|
|
hey .. hmmm, I'd start w/checking that f.Files.Count is actually greater than 1.. perhaps the file count is not getting correctly set, or the directory/file collection is not being properly built, that would definitely cause the error you are encountering.
In my limited testing and use it worked, but, I basically use this library to upload files to an FTP server and I am not looping through a collection.
I wish I could be more specific. I can say, if you are using the library in a console app (as I am) try outputing enough information to the console to help you determine where the breakdown is occuring.
Jmers
|
|
|
|
|
Thanks for the lib Jmers but
has someone fixed this please?
I can get only one file copied...
<this.Count> egal 0 for the 2nd file in the <public File this[string sIndex]>
Thanks!
|
|
|
|
|
Just change the inner conditional in RebuildFileList():
if ((f[0] != 'd') && (f.ToUpper().IndexOf("<DIR>") <= 0))
{
this.Add(f);
}
The IndexOf("DIR") returns -1 instead of zero.
|
|
|
|
|
Yes, this is the fix. Open the project, make the above change and recompile. I'm sure I'll run up against this again in the future so: Hey Jeff, this works - make the change and redeploy the dll.
|
|
|
|
|
Hi,
Can you explain to me how to get the directories listing?
When I tried to do that, the input I got was "System.String[]".
So how can I display the directoy's name?
Thanks.
|
|
|
|
|
Hi,
Sorry for the delay in responding, work has been busy.
You want to access the Directories object which is a collection of all of the directories. Its built automatically for you, when you access a directory, so in the example above (you could):
OpenFTP.FTP f = new OpenFTP.FTP();
f.Connect("127.0.0.1", "username_here", "password_here");
f.ChangeDirectory("somedirectory");
string sSomeDirName = "";
for(int i = 0; i <f.directories.count; i++)
{
="" ssomedirname="f.Directories[i].DirectoryName;
}
Hope" that="" helps,
james=""
<div="" class="ForumSig">Jmers
|
|
|
|
|
|
Thanks for the article, everything seems to work fine so far.
To be able to upload Read-only-files, I had to change this line of code in "public void Upload(string sRemoteFilename, string sLocalFilename, bool bResume)" though :
FTPPlumbing.file = new FileStream(sLocalFilename, FileMode.Open, FileAccess.Read);
instead of
FTPPlumbing.file = new FileStream(sLocalFilename, FileMode.Open);
regards,
|
|
|
|
|
Cool.. didn't even try it w/read-only files, very interesting. Thanx for the post.
Jmers
|
|
|
|
|
Is there some way to connect via Proxy
Thnx
|
|
|
|
|
Good question, I don't know. It seems like to me you could set the port to the port for your proxy and it might work, but I really don't know.
Jmers
|
|
|
|
|
the original project from J.P. Trosclair has a function to choose the FTP-Mode (active/passive).
in your implentation i didnt find this function. is this correct?
greetings from berlincity.
|
|
|
|
|
Its still there, line # 234 (if you haven't changed the code). I move it to the interal plumbing class. Hope that helps.
Jmers
|
|
|
|
|
i mean that the mode is no property from your OpenFTP-Class.
I cant set it. I can only set
string sServer, int iPort, string sUsername, string sPassword
|
|
|
|
|
My bad. I'll make a code update, in the interim if you change the internal class modifier to public on the FTPPlumbing class I believe you will be able to do what you need.
Jmers
|
|
|
|
|
yap, thanx a lot.
i have just added:
public bool PassiveMode
{
get { return FTPPlumbing.PassiveMode; }
set { FTPPlumbing.PassiveMode = value; }
}
and i think it works fine.
edit: and i miss another thing: the function "IsConnected", i think its an important feature, or?
public bool IsConnected
{
get { return (FTPPlumbing.IsConnected); }
}
-- modified at 18:33 Wednesday 30th May, 2007
i have the problem that the upload only transfer 512 bytes from a file. after this, the upload wait until timeout. do u have any idea? i use a localnetwork filezilla ftp server (passive mode).
-- modified at 6:47 Thursday 31st May, 2007
okay i have found my mistake, i didnt use the while-loop ->
while (!ftpConnection.Files.UploadComplete)
and without this entry it doenst work.
|
|
|
|
|
Hi,
For some reason i cant get it to fully work.
I took your example, and made this out of it.
<br />
string filePath = "C:\\servers.xml";<br />
ServerDataSet.WriteXml(filePath);<br />
<br />
OpenFTP.FTP openFTP = new OpenFTP.FTP();<br />
string remotefile = "servers.xml";<br />
openFTP.Connect("blele.com", "test", "test");<br />
openFTP.ChangeDirectory(@"flxdesigns.net");<br />
openFTP.Files.Upload(remotefile, filePath, true);<br />
openFTP = null;<br />
openFTP.Disconnect();<br />
When i execute it, JIT spits out "System.FormatException: Input string was not in a correct format."
What am I doing wrong?
Regards,
Dennis
-- modified at 14:17 Wednesday 30th May, 2007
|
|
|
|
|
Hello,
The error happens in the ChangeDirectory method, exactly in Add().
public void Add(string sUnparsedFile)
{
string sFileName = sUnparsedFile.Substring(39).Trim().Replace("\r","");
long lFileSize = long.Parse(sUnparsedFile.Substring(17, 21).Trim());
DateTime dtFileDate = Convert.ToDateTime(sUnparsedFile.Substring(0, 8) + " " + sUnparsedFile.Substring(10, 7));
Add(sFileName, lFileSize, dtFileDate);
}
Look: http://www.codeproject.com/cs/library/ftp_class_library.asp?msg=2052065#xx2052065xx[^]
Somebody had the problem as well!
flxfxp wrote: openFTP = null;
openFTP.Disconnect();
This will not work!
openFTP.Disconnect();
openFTP = null;
flxfxp wrote: (@"flxdesigns.net");
The "@" is not neccesary!
So I think you have to wait until an update is made!
P.S.:posting your complete connect params is not such a good idea!
All the best,
Martin
|
|
|
|