Dim ff As FTPFactory = New FTPFactory ff.setDebug(True) ff.setRemoteHost("192.168.0.30") ff.setRemoteUser("jaimon") ff.setRemotePass("mathew") ff.login() ff.chdir("incoming")
Den siger "Declaration expected" på mine ff'er men de burde jo være dekleret med "Dim ff As FTPFactory = New FTPFactory"
Det kan være at jeg har compilet dll'en forkert?
Det er denne her: /* FTPFactory.cs Better view with tab space=4
Written by Jaimon Mathew (jaimonmathew@rediffmail.com) Rolander,Dan (Dan.Rolander@marriott.com) has modified the download method to cope with file name with path information. He also provided the XML comments so that the library provides Intellisense descriptions.
use the following line to compile csc /target:library /out:FTPLib.dll /r:System.DLL FTPFactory.cs */
using System; using System.Net; using System.IO; using System.Text; using System.Net.Sockets;
namespace FtpLib {
public class FTPFactory {
private string remoteHost,remotePath,remoteUser,remotePass,mes; private int remotePort,bytes; private Socket clientSocket;
/// /// Set the name of the FTP server to connect to. /// /// Server name public void setRemoteHost(string remoteHost) { this.remoteHost = remoteHost; }
/// /// Return the name of the current FTP server. /// /// Server name public string getRemoteHost() { return remoteHost; }
/// /// Set the port number to use for FTP. /// /// Port number public void setRemotePort(int remotePort) { this.remotePort = remotePort; }
/// /// Return the current port number. /// /// Current port number public int getRemotePort() { return remotePort; }
/// /// Set the remote directory path. /// /// The remote directory path public void setRemotePath(string remotePath) { this.remotePath = remotePath; }
/// /// Return the current remote directory path. /// /// The current remote directory path. public string getRemotePath() { return remotePath; }
/// /// Set the user name to use for logging into the remote server. /// /// Username public void setRemoteUser(string remoteUser) { this.remoteUser = remoteUser; }
/// /// Set the password to user for logging into the remote server. /// /// Password public void setRemotePass(string remotePass) { this.remotePass = remotePass; }
/// /// Return a string array containing the remote directory's file list. /// /// /// public string[] getFileList(string mask) {
/// /// Login to the remote server. /// public void login() {
clientSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); IPEndPoint ep = new IPEndPoint(Dns.Resolve(remoteHost).AddressList[0], remotePort);
try { clientSocket.Connect(ep); } catch(Exception) { throw new IOException("Couldn't connect to remote server"); }
logined = true; Console.WriteLine("Connected to "+remoteHost);
chdir(remotePath);
}
/// /// If the value of mode is true, set binary mode for downloads. /// Else, set Ascii mode. /// /// public void setBinaryMode(Boolean mode) {
if(mode) { sendCommand("TYPE I"); } else { sendCommand("TYPE A"); } if (retValue != 200) { throw new IOException(reply.Substring(4)); } }
/// /// Download a file to the Assembly's local directory, /// keeping the same file name. /// /// public void download(string remFileName) { download(remFileName,"",false); }
/// /// Download a remote file to the Assembly's local directory, /// keeping the same file name, and set the resume flag. /// /// /// public void download(string remFileName,Boolean resume) { download(remFileName,"",resume); }
/// /// Download a remote file to a local file name which can include /// a path. The local file name will be created or overwritten, /// but the path must exist. /// /// /// public void download(string remFileName,string locFileName) { download(remFileName,locFileName,false); }
/// /// Download a remote file to a local file name which can include /// a path, and set the resume flag. The local file name will be /// created or overwritten, but the path must exist. /// /// /// /// public void download(string remFileName,string locFileName,Boolean resume) { if(!logined) { login(); }
setBinaryMode(true);
Console.WriteLine("Downloading file "+remFileName+" from "+remoteHost + "/"+remotePath);
if (locFileName.Equals("")) { locFileName = remFileName; }
if(!File.Exists(locFileName)) { Stream st = File.Create(locFileName); st.Close(); }
FileStream output = new FileStream(locFileName,FileMode.Open);
Socket cSocket = createDataSocket();
long offset = 0;
if(resume) {
offset = output.Length;
if(offset > 0 ) { sendCommand("REST "+offset); if(retValue != 350) { //throw new IOException(reply.Substring(4)); //Some servers may not support resuming. offset = 0; } }
if(offset > 0) { if(debug) { Console.WriteLine("seeking to " + offset); } long npos = output.Seek(offset,SeekOrigin.Begin); Console.WriteLine("new pos="+npos); } }
/// /// Delete a file from the remote FTP server. /// /// public void deleteRemoteFile(string fileName) {
if(!logined) { login(); }
sendCommand("DELE "+fileName);
if(retValue != 250) { throw new IOException(reply.Substring(4)); }
}
/// /// Rename a file on the remote FTP server. /// /// /// public void renameRemoteFile(string oldFileName,string newFileName) {
if(!logined) { login(); }
sendCommand("RNFR "+oldFileName);
if(retValue != 350) { throw new IOException(reply.Substring(4)); }
// known problem // rnto will not take care of existing file. // i.e. It will overwrite if newFileName exist sendCommand("RNTO "+newFileName); if(retValue != 250) { throw new IOException(reply.Substring(4)); }
}
/// /// Create a directory on the remote FTP server. /// /// public void mkdir(string dirName) {
if(!logined) { login(); }
sendCommand("MKD "+dirName);
if(retValue != 250) { throw new IOException(reply.Substring(4)); }
}
/// /// Delete a directory on the remote FTP server. /// /// public void rmdir(string dirName) {
if(!logined) { login(); }
sendCommand("RMD "+dirName);
if(retValue != 250) { throw new IOException(reply.Substring(4)); }
}
/// /// Change the current working directory on the remote FTP server. /// /// public void chdir(string dirName) {
if(dirName.Equals(".")) { return; }
if(!logined) { login(); }
sendCommand("CWD "+dirName);
if(retValue != 250) { throw new IOException(reply.Substring(4)); }
this.remotePath = dirName;
Console.WriteLine("Current directory is "+remotePath);
}
/// /// Close the FTP connection. /// public void close() {
Socket s = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); IPEndPoint ep = new IPEndPoint(Dns.Resolve(ipAddress).AddressList[0], port);
try { s.Connect(ep); } catch(Exception) { throw new IOException("Can't connect to remote server"); }
Tilføjede reference til FTPLib.dll og så compilede dette:
Imports System
Imports FtpLib
Module Main Sub Main() Dim ff As FTPFactory = New FTPFactory ff.setDebug(True) ff.setRemoteHost("192.168.0.30") ff.setRemoteUser("jaimon") ff.setRemotePass("mathew") ff.login() ff.chdir("incoming") Dim fileNames() As String = ff.getFileList("*.*") End Sub End Module
Dim ff As FTPFactory = New FTPFactory ff.setDebug(True) ff.setRemoteHost("192.168.0.30") ff.setRemoteUser("jaimon") ff.setRemotePass("mathew") ff.login() ff.chdir("incoming") Dim fileNames() As String = ff.getFileList("*.*")
Nå, men når den downloader så kan jeg godt sende antal bytes sendt via console.write i cs filen, men jeg ville jo gerne kunne bruge det i min vb som loader dll'en så jeg kunne lave en processbar, eler noget.
Det jeg har brug for er at den sender antal byte når de er skrevet til en variabel jeg så kan bruge... forstår du?
Det jeg tror at du skal er: - lave en variabel i klassen som indeholder antal bytes up eller downloadet - lade start på upload/download sætte den til nul - tælle den løbende op under upload/download med antal bytes - lave en metode/property som returnerer den variabel
Så har du det du skal bruge.
Så skal din VB kode bare starte upload/download og opdatere progress bar samtidigt. Det kræver nok en ekstra tråd.
Mine problemer står i at jeg gerne vil kunne uploade og downloade til ftp fra min app... andet er det faktisk ikke... Jeg har også lidt problemer med den der ftp cs dll lib ting... Den kan ikke overføre mere end 7-8 filer afgangen så stopper den...
Nu er jeg jo ikke HARDCORE til CS, men det må da også kunne lade sig gøre bare i vb
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.