ftp取文件java代码 ftps java( 五 )


if(remoteSize0){
status = result?UploadStatus.Upload_From_Break_Success:UploadStatus.Upload_From_Break_Failed;
}else {
status = result?UploadStatus.Upload_New_File_Success:UploadStatus.Upload_New_File_Failed;
}
return status;
}
public static void main(String[] args) {
ContinueFTP myFtp = new ContinueFTP();
try {
System.err.println(my("10.10.6.236", 21, "5", "jieyan"));
//my(new String("歌曲".getBytes("GBK"),"iso-8859-1"));
//my(new String("歌曲".getBytes("GBK"),"iso-8859-1"));
//my(new String("爱你等于爱自己".getBytes("GBK"),"iso-8859-1"));
//System.out.println(my("E:\\yw.flv", "/yw.flv",5));
//System.out.println(my("E:\\爱你等于爱自己.mp4","/爱你等于爱自己.mp4"));
//System.out.println(my("/爱你等于爱自己.mp4", "E:\\爱你等于爱自己.mp4"));
my;
} catch (IOException e) {
System.out.println("连接FTP出错:"+e.getMessage());
}
}
}
求每日定时在服务器的FTP上取数据文件的源码(JAVA)这个是可以向服务器端发送文字的程序,就是在客户端发送一句hello在服务器也可以接受到hello,这个程序可以修改一下就可以了 。具体修改方法是增加一个定时器,然后把字符流改成字节流,现在有点忙 , 你先研究?。教彀锬阈葱纯?。
服务器端:
import java.net.*;
import java.io.*;
public class DateServer {
public static void main(String[] args) {
ServerSocket server=null;
try{
server=new ServerSocket(6666);
System.out.println(
"Server start on port 6666...");
while(true){
Socket socket=server.accept();
new SocketHandler(socket).start();
/*
PrintWriter out=new PrintWriter(
new OutputStreamWriter(
socket.getOutputStream()
)
);
out.println(new java.util.Date().toLocaleString());
out.close();
*/
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(server!=null) {
try{
server.close();
}catch(Exception ex){}
}
}
}
}
class SocketHandler extends Thread {
private Socket socket;
public SocketHandler(Socket socket) {
this.socket=socket;
}
public void run() {
try{
PrintWriter out=new PrintWriter(
new OutputStreamWriter(
socket.getOutputStream()
)
);
out.println(
new java.util.Date().
toLocaleString());
out.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
客户端:
package com.briup;
import java.io.*;
import java.net.*;
public class FtpClient {
public static void main(String[] args) {
if(args.length==0) {
System.out.println("Usage:java FtpClient file_path");
System.exit(0);
}
File file=new File(args[0]);
if(!file.exists()||!file.canRead()) {
System.out.println(args[0]+" doesn't exist or can not read.");
System.exit(0);
}
Socket socket=null;
try{
socket=new Socket(args[1],Integer.parseInt(args[2]));
BufferedInputStream in=new BufferedInputStream(
new FileInputStream(file)
);
BufferedOutputStream out=new BufferedOutputStream(
socket.getOutputStream()
);
byte[] buffer=new byte[1024*8];
int i=-1;
while((i=in.read(buffer))!=-1) {
out.write(buffer,0,i);
}
System.out.println(socket.getInetAddress().getHostAddress()+" send file over.");
in.close();
out.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(socket!=null) {
try{
socket.close();
}catch(Exception ex){}
}
}
}
}
关于ftp取文件java代码和ftps java的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读