服务器端:
import javanet;
import javaio;
public class DateServer {
public static void main(String[] args) {
ServerSocket server=null;
try{
server=new ServerSocket(6666);
Systemoutprintln(
"Server start on port 6666");
while(true){
Socket socket=serveraccept();
new SocketHandler(socket)start();
/
PrintWriter out=new PrintWriter(
new OutputStreamWriter(
socketgetOutputStream()
)
);
outprintln(new javautilDate()toLocaleString());
outclose();
/
}
}catch(Exception e){
eprintStackTrace();
}finally{
if(server!=null) {
try{
serverclose();
}catch(Exception ex){}
}
}
}
}
class SocketHandler extends Thread {
private Socket socket;
public SocketHandler(Socket socket) {
thissocket=socket;
}
public void run() {
try{
PrintWriter out=new PrintWriter(
new OutputStreamWriter(
socketgetOutputStream()
)
);
outprintln(
new javautilDate()
toLocaleString());
outclose();
}catch(Exception e){
eprintStackTrace();
}
}
}
客户端:
package combriup;
import javaio;
import javanet;
public class FtpClient {
public static void main(String[] args) {
if(argslength==0) {
Systemoutprintln("Usage:java FtpClient file_path");
Systemexit(0);
}
File file=new File(args[0]);
if(!fileexists()||!filecanRead()) {
Systemoutprintln(args[0]+" doesn't exist or can not read");
Systemexit(0);
}
Socket socket=null;
try{
socket=new Socket(args[1],IntegerparseInt(args[2]));
BufferedInputStream in=new BufferedInputStream(
new FileInputStream(file)
);
BufferedOutputStream out=new BufferedOutputStream(
socketgetOutputStream()
);
byte[] buffer=new byte[10248];
int i=-1;
while((i=inread(buffer))!=-1) {
outwrite(buffer,0,i);
}
Systemoutprintln(socketgetInetAddress()getHostAddress()+" send file over");
inclose();
outclose();
}catch(Exception e){
eprintStackTrace();
}finally{
if(socket!=null) {
try{
socketclose();
}catch(Exception ex){}
}
}
}
}用flashfxp 工具上传到服务器 前提是你需要有服务器上有 *** 作空间权限的用户名和密码如果是ASP的 或者NET的 传完用IIS配置网站文件夹安全也需要增加一个对应文件夹的用户 或者everyone用户 来给它写权限还要记得IIS配置里开启父路径
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)