Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing a remote SUN SOLARIS machine from windows

Status
Not open for further replies.

dilse

Programmer
Jul 21, 2001
6
IN
I have a problem to get the files in a remote machine where we have the permission as a user.We r supposed to get some files(.txt) from there . We are getting NullpointerException

Anybody can help ???
The code is as follows...............



-------------------------------------------------------
import sun.net.*;
import sun.net.ftp.*;
import java.io.*;


class OnlyExt implements FilenameFilter
{
String ext;
public OnlyExt(String ext)
{
this.ext="."+ext;
}
public boolean accept(File dir,String name)
{
return name.endsWith(ext);
}
}

class myftp1
{
public static void main(String args[])
{
String site = "203.199.121.103";
String login = "soc1";// **ENTER YOUR OWN Login
String password = "soc1";// **ENTER YOUR OWN PASSWORD
String dirname = "/flatfiles";
//// file on local machine to put on ftp site
//String fileToPut = "hod"; //**ENTER YOUR ONW FILENAME
// file on ftp site to put on local machine

FtpClient fc;
TelnetInputStream tis;
TelnetOutputStream tos;
FileInputStream fis;
FileOutputStream fos;
FilenameFilter only = new OnlyExt("txt");
int i;
File f1=new File(dirname);//flatfiles is the name of the directory
byte inbyte;

try
{
//// connect to the site
fc = new FtpClient(site);
//// print the site's response
System.out.println(fc.getResponseString());

//// send login and password
fc.login(login,password);
//// print the site's response
System.out.println(fc.getResponseString());

String f[]=f1.list(only);//This line extracts all filenames with extension name .txt
System.out.println("No of files is ");

//// print the site's response
System.out.println(fc.getResponseString());
System.out.println("The current path is "+f1.getPath());
System.out.println("The number of file found is ");
for (int a=0;a<f.length;a++)
{

tis = fc.get(f[a]);
System.out.println(fc.getResponseString());
//// create that file on the local machine
fos = new FileOutputStream(new File(f[a]));
while((i=tis.read())!=-1) // read file from site
{
inbyte = (byte) i;
fos.write(inbyte); // write file to local file
}
fos.close();

} //end of for loop
}//end of try block
catch(Exception e)
{
System.err.println(&quot;ERROR: &quot; + e);
}
}// end of main()
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top