 |
|
 |
Hello,
This programm looks great, but I have a problem.
I can't change the property of the directory that I sent to ftp server.
(The file that I send is read only)
Could you help me ?
Thank you very much!
wen
|
|
|
|
 |
|
 |
This is a very nice FTP client!
Very Impressive to say the least, your effort shows.
|
|
|
|
 |
|
 |
Does this support proxy?
Sunil
|
|
|
|
 |
|
 |
hi,Massimo,LigthFTPClient use as Passive FTP,it works good,but now,i need to use PORT mode,and do you know how to use this command?
this is my code
====================================
Dim strT As String
strT = "192,168,42,27,19,70"
'192.168.42.27:this ip is local ip
'19,70:that is randomly imported by me
sendCommand("PORT " & strT)
Dim ipAddress As String = Me.strServer
Dim port As Int32 = 19 * 256 + 70
Dim socket As Socket = Nothing
Dim ep As IPEndPoint = Nothing
socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
ep = New IPEndPoint(Dns.Resolve(ipAddress).AddressList(0), port)
socket.Connect(ep)
====================================
but this have a problem,when it execute to socket.Connect(ep),
there is no replay from server.
|
|
|
|
 |
|
 |
Hi,
LigthFTPClient was not built to use "active mode" (PORT mode), to use it I have to redesign the application logic (probably in the future I'll do it).
The following text explain how "active mode" works:
A client opens a connection to the FTP control port (port 21) of an FTP server. So that the server will be later able to send data back to the client machine, a second (data) connection must be opened between the server and the client.
To make this second connection, the client sends a PORT command to the server machine. This command includes parameters that tell the server which IP address to connect to and which port to open at that address - in most cases this is intended to be a high numbered port on the client machine.
The server then opens that connection, with the source of the connection being port 20 on the server and the destination being the port identified in the PORT command parameters.
About your code
dongshan wrote: socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
ep = New IPEndPoint(Dns.Resolve(ipAddress).AddressList(0), port)
socket.Connect(ep)
To receive data from FTP server you must create a socket but you haven't to connect to it, the ftp server has to do.
You have to listen on it, you should change the code in this way (C# code, I hope it wasn't a problem)
....
socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
ep = new IPEndPoint(Dns.Resolve(ipAddress).AddressList[0], port);
socket.Bind(ep);
socket.Listen(1000);
socket.BeginAccept(new AsyncCallback(this.AcceptCallback), socket);
...
private void AcceptCallback(IAsyncResult ar)
{
Socket listener = (Socket) ar.AsyncState;
Socket handler = listener.EndAccept(ar);
Byte[] receiveBuffer = new Byte[1024];
string l_strOutput = "",l_strTemp = "";
for ( ; ( l_iRetval = handler.Receive(receiveBuffer)) > 0 ; )
{
l_strTemp = Encoding.ASCII.GetString(receiveBuffer,0,l_iRetval);
l_strOutput += l_strTemp;
if ( handler.Available == 0 )
{
break;
}
}
handler.Close();
}
I hope this can help you.
Bye
Massimo
-- modified at 11:00 Friday 1st September, 2006
|
|
|
|
 |
|
 |
thanks Massimo
|
|
|
|
 |
|
 |
hello Massimo,
In order to use your great code with Active mode, would that require the re-design of the whole application? or just the createDataSocket() function?
The posts here are from 2006. Have you changed this appplication lately?
Thank you!
Maximus
|
|
|
|
 |
|
 |
Hi,
I'm getting timeouts in the application, specifically around the following code in readLine() method:
for ( ; ( l_iRetval = clientSocket.Receive(receiveBuffer)) > 0 ; )
The file is being downloaded successfully but the client just becomes unresponsive - has anyone else had this problem?
Cheers
Si
|
|
|
|
 |
|
|
 |
|
 |
Hi,
I managed to sort out the problem, it was indeed in the Download method but was not covered by your previous answer.
The original code:
if ( cSocket.Connected ) cSocket.Close();
this.readResponse();
if( this.resultCode != 226 && this.resultCode != 250 )
FireException(this.result.Substring(4));
}
And the fixed code:
if ( cSocket.Connected ) cSocket.Close();
if(cSocket.Connected == true)
this.readResponse();
if( this.resultCode != 226 && this.resultCode != 250 )
FireException(this.result.Substring(4));
}
BAsically i'm checking to be sure the socket is still actually connected, if not then skip reading any more responses, otherwise carry on as normal. What appeared to be happening was the socket was being closed then you were reading more data from the socket hence the deadlock - this fix addresses the problem I experienced.
I'm surprised no one else has had the same problem though, really surprised!
Regards
Si
|
|
|
|
 |
|
 |
Many thaks for your fixed code.
Bye
Massimo
|
|
|
|
 |
|
 |
That helped me too, thanks!
|
|
|
|
 |
|
 |
I have a few additions that I added to the existing code:
Ability to create/remove directories
Upload multiple files at a time
Should I just post it here? Or you want it?
|
|
|
|
 |
|
 |
Thanks for your addition,
please send me your code and I'll include it with a reference to you in comments.
Then as soon as possible I'll update my article.
However if you want to share immediatly your code post it in this forum too.
Thanks again
Massimo
|
|
|
|
 |
|
 |
Sure, here's the beef of what I've completed so far.
Enable multiple select on the lvLocalFiles. Then modify lvFiles_DragDrop to:
private void lvFiles_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
foreach(ListViewItem lvi in lvLocalFiles.SelectedItems)
{
if ((CurrentEffect == DragDropEffects.Copy) && (((ListView)sender).Name != startingFrom))
{
if(lvi.ImageIndex == INDEX_TAG_FILE)
UploadFile(sLocalPath+ (sLocalPath.EndsWith("\\")?"":"\\")+lvi.SubItems[1].Text, false);
else if (lvi.ImageIndex == INDEX_TAG_DIR)
UploadDirectory(sLocalPath+ (sLocalPath.EndsWith("\\")?"":"\\")+lvi.SubItems[1].Text, true);
}
}
GetFileList("");
}
Modify contextMenuRemote by adding a "Create Directory..." item. Call this method when a user clicks the item:
///
/// Create a new folder on the remote server.
///
///
private void CreateFolder()
{
frmCreateDirectory frm = new frmCreateDirectory();
string folder = string.Empty;
if((folder = frm.ShowModal()) != string.Empty)
{
try
{
ftpClient.MakeDir(folder);
}
catch (FtpClient.FtpException ex)
{
Warning("", ex.Message);
}
finally
{
this.GetFileList("");
}
}
}
Add new Form frmCreateDirectory:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace LightFTPClient
{
///
/// Summary description for frmCreateDirectory.
///
public class frmCreateDirectory : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.TextBox txtDirectory;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public frmCreateDirectory()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
public string ShowModal()
{
string retval = txtDirectory.Text;
txtDirectory.SelectAll();
if (this.ShowDialog() == DialogResult.OK)
{
retval = txtDirectory.Text;
}
return retval;
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.txtDirectory = new System.Windows.Forms.TextBox();
this.btnOk = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtDirectory
//
this.txtDirectory.Location = new System.Drawing.Point(8, 16);
this.txtDirectory.Name = "txtDirectory";
this.txtDirectory.Size = new System.Drawing.Size(176, 20);
this.txtDirectory.TabIndex = 0;
this.txtDirectory.Text = "";
//
// btnOk
//
this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOk.Location = new System.Drawing.Point(8, 56);
this.btnOk.Name = "btnOk";
this.btnOk.TabIndex = 1;
this.btnOk.Text = "Ok";
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(104, 56);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 2;
this.btnCancel.Text = "Cancel";
//
// frmCreateDirectory
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(192, 85);
this.ControlBox = false;
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.txtDirectory);
this.Name = "frmCreateDirectory";
this.Text = "Create New Directory";
this.ResumeLayout(false);
}
#endregion
}
}
Modify frmMain.menuItem3_Click:
private void menuItem3_Click(object sender, System.EventArgs e)
{
// delete
ListViewItem lvItem;
ListView lv = (ListView)(contextMenuRemote.SourceControl);
if (lv.SelectedIndices.Count > 0)
{
lvItem = lv.SelectedItems[0];
if (lvItem.ImageIndex == INDEX_TAG_FILE)
{
DeleteFile(lvItem.SubItems[1].Text);
GetFileList("");
}
else
if(lvItem.ImageIndex == INDEX_TAG_DIR)
{
ftpClient.RemoveDir(lvItem.SubItems[1].Text);
GetFileList("");
}
}
}
I've only tested a few times, but everything seems to be working. Hope this helps
|
|
|
|
 |
|
 |
Hello,
This programm looks great, but I have a problem, I can't connect my FTP server because I have this result :
invalid response for PASV command
Could you help me ?
Regards
|
|
|
|
 |
|
 |
Hi,
only the error message is not enough to help you.
2 steps towards the solution:
1. try to connect to your ftp via command line using the same commands and note if it works
2. send me your ftp address so I can make a test
Bye
Massimo
|
|
|
|
 |
|
 |
Thanks for your response.
1. try to connect to your ftp via command line using the same commands and note if it works
--> I don't understand how do this.
2. send me your ftp address so I can make a test
--> the server is ftp.numericable.fr but it is not an anonymous server. I can't give you my password.
For information it is not ths first time I test a ftp program and always I have this PASV error. I usually use FileZilla and it works fine but I need to add functionnality so your software interest me
|
|
|
|
 |
|
 |
Ok,
open a DOS prompt window then write:
1. ftp ftp.numericable.fr ENTER then wait response
2. user "your username" ENTER then wait response
3. pass "your password" ENTER then wait response
4. SYST ENTER then wait response
5. PWD ENTER then wait response
6. PASV ENTER then wait response
7. LIST ENTER then wait response
Try this and verify if it works in PASSIVE MODE.
Let me know.
Bye
Massimo
|
|
|
|
 |
|
 |
I have lots of error :
ftp ftp.numericable.fr
Connecté à ftp.numericable.fr.
220 dummer.numericable.net FTP server ready
Utilisateur (ftp.numericable.fr:(none)) : ***********
331 Password required for ***********.
Mot de passe :
230 User sdelestre10 logged in.
ftp> SYST
Commande non valide.
ftp> PWD
257 "/" is current directory.
ftp> PASV
Commande non valide.
ftp> LIST
Commande non valide.
ftp>
|
|
|
|
 |
|
 |
Hi,
try to use the following commands
ftp> SYST ====> use literal SYST ENTER. This is not necessary but it shows the S.O. of your ftp server.
ftp> PASV ====> use literal PASV ENTER
and see if your ftp server support passive mode.
Bye
Massimo
|
|
|
|
 |
|
 |
Exactly same message :
ftp ftp.numericable.fr
Connecté à ftp.numericable.fr.
220 dummer.numericable.net FTP server ready
Utilisateur (ftp.numericable.fr:(none)) : *******
331 Password required for ********.
Mot de passe :
230 User ******** logged in.
ftp> SYST ENTER
Commande non valide.
ftp> PWD ENTER
257 "/" is current directory.
ftp> PASV ENTER
Commande non valide.
ftp> LIST ENTER
Commande non valide.
ftp>
-- modified at 9:22 Wednesday 1st March, 2006
With FileZilla :
Etat : Connexion à ftp.numericable.fr ...
Etat : Connecté à ftp.numericable.fr. Attente du message d'accueil...
Réponse : 220 dummer.numericable.net FTP server ready
Commande : USER *******
Réponse : 331 Password required for *******.
Commande : PASS *******
Réponse : 230 User *******logged in.
Commande : FEAT
Réponse : 500 FEAT not understood.
Commande : SYST
Réponse : 215 UNIX Type: L8
Etat : Connecté
Etat : Récupération de la liste de répertoires...
Commande : PWD
Réponse : 257 "/" is current directory.
Commande : TYPE A
Réponse : 200 Type set to A.
Commande : PORT 192,168,1,143,17,47
Réponse : 200 PORT command successful.
Commande : LIST
Réponse : 150 Opening ASCII mode data connection for file list.
Réponse : 226-Transfer complete.
Réponse : 226 Quotas on: using 14.78 of 200.00 MB
Etat : Succès du listage du répertoire
Commande : TYPE A
Réponse : 200 Type set to A.
Commande : REST 0
Réponse : 350 Restarting at 0. Send STORE or RETRIEVE to initiate transfer.
Réponse : 421 No Transfer Timeout (60 seconds): closing control connection.
Erreur : Déconnecté du serveur
Etat : Attente de relance... (encore 5 tentatives)
Etat : Connexion à ftp.numericable.fr ...
Etat : Connecté à ftp.numericable.fr. Attente du message d'accueil...
Réponse : 220 dummer.numericable.net FTP server ready
Commande : USER *******
Réponse : 331 Password required for sdelestre10.
Commande : PASS *******
Réponse : 230 User *******logged in.
Commande : FEAT
Réponse : 500 FEAT not understood.
Commande : SYST
Réponse : 215 UNIX Type: L8
Etat : Connecté
|
|
|
|
 |
|
 |
There was a misunderstand...
after the ftp server send its response to your password
type all the word in red (literal is a ftp keyword) the press ENTER:
literal SYST
wait the response
literal PASV
wait the response.
See the message of your ftp server to this last command.
Bye
Massimo
|
|
|
|
 |
|
 |
Sorry I have not understand "literal"
so the result is :
ftp ftp.numericable.fr
Connecté à ftp.numericable.fr.
220 dummer.numericable.net FTP server ready
Utilisateur (ftp.numericable.fr:(none)) : sdelestre10
331 Password required for sdelestre10.
Mot de passe :
230 User sdelestre10 logged in.
ftp> literal SYST
215 UNIX Type: L8
ftp> literal PWD
257 "/" is current directory.
ftp> literal PASV
500 The server returned invalid response for PASV command.
ftp> literal LIST
Connexion fermée par l'hôte distant.
ftp>
thanks for your big help
|
|
|
|
 |
|
 |
It seems that your ftp server doesn't support "passive mode".
That's all.
Massimo
|
|
|
|
 |