public int login(String username, String password)
{
this.username = username;
this.password = password;
int status = LOGIN_OK;
jcon = new JConnection(host, port);
if(jcon.isThere())
{
in = jcon.getReader();
if(getLine(POSITIVE) == null)//FTP220_SERVICE_READY) == null)
{
ok = false;
status = OFFLINE;
}
if(!getLine(loginAck).startsWith(POSITIVE))//FTP230_LOGGED_IN))
{
if(success(POSITIVE))//FTP230_LOGGED_IN))
{
}
else
{
ok = false;
status = WRONG_LOGIN_DATA;
}
}
}
else
{
if(msg)
{
Log.debug("FTP not available!");
ok = false;
status = GENERIC_FAILED;
}
}
if(ok)
{
connected = true;
system();
binary();
String[] advSettings = new String[6];
if(getOsType().indexOf("OS/2") >= 0)
{
LIST_DEFAULT = "LIST";
}
if(LIST.equals("default"))
{
//just get the first item (somehow it knows first is the
//FTP list command)
advSettings = LoadSet.loadSet(Settings.adv_settings);
//*** IF FILE NOT FOUND, CREATE IT AND SET IT TO LIST_DEFAULT
if(advSettings == null)
{
LIST = LIST_DEFAULT;
SaveSet s = new SaveSet(Settings.adv_settings, LIST);
}
else
{
LIST = advSettings[0];
if(LIST == null)
{
LIST = LIST_DEFAULT;
}
}
}
if(getOsType().indexOf("MVS") >= 0)
{
LIST = "LIST";
}
//***
fireDirectoryUpdate(this);
fireConnectionInitialized(this);
}
else
{
fireConnectionFailed(this, new Integer(status).toString());
}
return status;
}
public void run()
{
try
{
s = new Socket(host, port);
localPort = s.getLocalPort();
//if(time > 0) s.setSoTimeout(time);
out = new PrintStream(new BufferedOutputStream(s.getOutputStream(),
Settings.bufferSize));
in = new BufferedReader(new InputStreamReader(s.getInputStream()),
Settings.bufferSize);
isOk = true;
// }
}
catch(Exception ex)
{
ex.printStackTrace();
Log.out("WARNING: connection closed due to exception (" + host +
":" + port + ")");
isOk = false;
try
{
if((s != null) && !s.isClosed())
{
s.close();
}
if(out != null)
{
out.close();
}
if(in != null)
{
in.close();
}
}
catch(Exception ex2)
{
ex2.printStackTrace();
Log.out("WARNING: got more errors trying to close socket and streams");
}
}
established = true;
}
public int handleUpload(String file, String realName)
{
if(Settings.getEnableMultiThreading() &&
(!Settings.getNoUploadMultiThreading()))
{
Log.out("spawning new thread for this upload.");
FtpTransfer t;
if(realName != null)
{
t = new FtpTransfer(host, port, getLocalPath(), getCachedPWD(),
file, username, password, Transfer.UPLOAD,
handler, listeners, realName, crlf);
}
else
{
t = new FtpTransfer(host, port, getLocalPath(), getCachedPWD(),
file, username, password, Transfer.UPLOAD,
handler, listeners, crlf);
}
lastTransfer = t;
return NEW_TRANSFER_SPAWNED;
}
else
{
if(Settings.getNoUploadMultiThreading())
{
Log.out("upload multithreading is disabled.");
}
else
{
Log.out("multithreading is completely disabled.");
}
return (realName == null) ? upload(file) : upload(file, realName);
}
}
public void run()
{
if(handler.getConnections().get(file) == null)
{
handler.addConnection(file, this);
}
else if(!pause)
{
Log.debug("Transfer already in progress: " + file);
work = false;
stat = 2;
return;
}
boolean hasPaused = false;
while(pause)
{
try
{
runner.sleep(100);
if(listeners != null)
{
for(int i = 0; i < listeners.size(); i++)
{
((ConnectionListener) listeners.elementAt(i)).updateProgress(file,
PAUSED,
-1);
}
}
if(!work)
{
if(listeners != null)
{
for(int i = 0; i < listeners.size(); i++)
{
((ConnectionListener) listeners.elementAt(i)).updateProgress(file,
REMOVED,
-1);
}
}
}
}
catch(Exception ex)
{
}
hasPaused = true;
}
while((handler.getConnectionSize() >= Settings.getMaxConnections()) &&
(handler.getConnectionSize() > 0) && work)
{
try
{
stat = 4;
runner.sleep(400);
if(!hasPaused && (listeners != null))
{
for(int i = 0; i < listeners.size(); i++)
{
((ConnectionListener) listeners.elementAt(i)).updateProgress(file,
QUEUED,
-1);
}
}
else
{
break;
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
if(!work)
{
if(listeners != null)
{
for(int i = 0; i < listeners.size(); i++)
{
((ConnectionListener) listeners.elementAt(i)).updateProgress(file,
REMOVED,
-1);
}
}
handler.removeConnection(file);
stat = 3;
return;
}
started = true;
try
{
runner.sleep(Settings.ftpTransferThreadPause);
}
catch(Exception ex)
{
}
con = new FtpConnection(host, port, remotePath, crlf);
con.setConnectionHandler(handler);
con.setConnectionListeners(listeners);
int status = con.login(user, pass);
if(status == FtpConnection.LOGIN_OK)
{
File f = new File(localPath);
con.setLocalPath(f.getAbsolutePath());
if(type.equals(UPLOAD))
{
if(newName != null)
{
transferStatus = con.upload(file, newName);
}
else
{
transferStatus = con.upload(file);
}
}
else
{
transferStatus = con.download(file,this.newName);
}
}
if(!pause)
{
handler.removeConnection(file);
}
}
public int upload(String file, String realName, InputStream in)
{
hasUploaded = true;
Log.out("ftp upload started: " + this);
int stat;
if((in == null) && new File(file).isDirectory())
{
shortProgress = true;
fileCount = 0;
baseFile = file;
dataType = DataConnection.PUTDIR;
isDirUpload = true;
stat = uploadDir(file);
shortProgress = false;
//System.out.println(fileCount + ":" + baseFile);
fireProgressUpdate(baseFile,
DataConnection.DFINISHED + ":" + fileCount, -1);
fireActionFinished(this);
fireDirectoryUpdate(this);
}
else
{
dataType = DataConnection.PUT;
stat = rawUpload(file, realName, in);
try
{
Thread.sleep(100);
}
catch(Exception ex)
{
}
fireActionFinished(this);
fireDirectoryUpdate(this);
}
try
{
Thread.sleep(500);
}
catch(Exception ex)
{
}
return stat;
}
protected void updateProgressBar() {
int percent = (int) (((float) lFileCompleteSize / (float) lFileSize) * 10000F);
pbFile.setValue(percent);
// System.out.println("================================================="+percent);
pbFile.setString(lFileCompleteSize / 1024L + "/" + lFileSize / 1024L
+ " kB");
percent = (int) (((float) lTotalCompleteSize / (float) lTotalSize) * 10000F);
pbTotal.setString(lTotalCompleteSize / 1024L + "/" + lTotalSize / 1024L
+ " kB");
pbTotal.setValue(percent);
repaint();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有