Archive

Posts Tagged ‘FTP Client’

FTP Client Using Apache Common net library using Socks Proxy Server

August 2, 2012 1 comment

As we have the FTP Server code in previous post, here is a FTP Client using Apache Commons library.  Below is a basic code which we can use to connect to our FTP server which we created over a SOCKS Proxy Server. (Assuming you have a SOCKS proxy server running already – if not then code can be used just as a FTP Client to connect directly to FTP Server).

Below Image shows, libraries required and parameter passed from the build.xml (this can be done over the command line as well)

1

Below Image shows changes required to Route all Packets to go through Proxy Server

2

 

Libraries Required.

<path id="FtpClientDemo.classpath">
        <pathelement location="bin"/>
        <pathelement location="lib/commons-net-3.1-ftp.jar"/>
        <pathelement location="lib/commons-net-3.1.jar"/>
    </path>

Sample Arg in Build.xml File

<target name="FtpClientDemo">
    <java classname="com.ftp.client.FtpClient" failonerror="true" fork="yes">
        <jvmarg line="-Djava.net.preferIPv4Stack=true"/>
        <!-- Proxy Argument Below -->
        <!-- <arg line="-PrH 192.168.0.201:1080 -p true -b -s 192.168.0.100 sipl sipl LookAppCode.rar f:\LookAppCode.rar"/> -->
        <!-- Normal Connection to FTPServer without Proxy -->
        <arg line="-l 127.0.0.1:8080 ahmed ahmed"/>
        <classpath refid="FtpClientDemo.classpath"/>
    </java>
</target>

Read more…