org.apache.commons.net.ftp.FTP Java Examples

The following examples show how to use org.apache.commons.net.ftp.FTP. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FTPUtil.java    From anyline with Apache License 2.0 6 votes vote down vote up
public void connect() { 
	try{ 
     client.connect(host, port);   
     int reply = client.getReplyCode();   
     if (!FTPReply.isPositiveCompletion(reply)) {   
         disconnect();   
     }   
     if ("".equals(account)) {   
     	account = "anonymous";   
     }   
     if (!client.login(account, password)) {   
         disconnect();   
     }   
     client.setFileType(FTP.BINARY_FILE_TYPE);   
     //ftp.setFileType(FTP.ASCII_FILE_TYPE);   
     client.enterLocalPassiveMode();  
	}catch(Exception e){ 
		e.printStackTrace(); 
	} 
       
}
 
Example #2
Source File: BugReportSenderFtp.java    From YalpStore with GNU General Public License v2.0 6 votes vote down vote up
private boolean uploadAll() {
    FTPClient ftpClient = new FTPClient();
    try {
        ftpClient.connect(FTP_HOST, FTP_PORT);
        if (!ftpClient.login(FTP_USER, FTP_PASSWORD)) {
            return false;
        }
        String dirName = getDirName();
        ftpClient.makeDirectory(dirName);
        ftpClient.enterLocalPassiveMode();
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE, FTP.BINARY_FILE_TYPE);
        ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
        boolean result = true;
        for (File file: files) {
            result &= upload(ftpClient, file, dirName + "/" + file.getName());
        }
        return result;
    } catch (IOException e) {
        Log.e(BugReportSenderFtp.class.getSimpleName(), "FTP network error: " + e.getMessage());
    } finally {
        closeSilently(ftpClient);
    }
    return false;
}
 
Example #3
Source File: FTPNetworkClient.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public boolean connectClient() throws IOException {
    boolean isLoggedIn = true;
    client.setAutodetectUTF8(true);
    client.setControlEncoding("UTF-8");
    client.connect(host, port);
    client.setFileType(FTP.BINARY_FILE_TYPE);
    client.enterLocalPassiveMode();
    client.login(username, password);
    int reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        client.disconnect();
        LogUtils.LOGD(TAG, "Negative reply form FTP server, aborting, id was {}:"+ reply);
        //throw new IOException("failed to connect to FTP server");
        isLoggedIn = false;
    }
    return isLoggedIn;
}
 
Example #4
Source File: FTPSNetworkClient.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public boolean connectClient() throws IOException {
    boolean isLoggedIn = true;
    client.setAutodetectUTF8(true);
    client.setControlEncoding("UTF-8");
    client.connect(host, port);
    client.setFileType(FTP.BINARY_FILE_TYPE);
    client.enterLocalPassiveMode();
    client.login(username, password);
    int reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        client.disconnect();
        LogUtils.LOGD(TAG, "Negative reply form FTP server, aborting, id was {}:"+ reply);
        //throw new IOException("failed to connect to FTP server");
        isLoggedIn = false;
    }
    return isLoggedIn;
}
 
Example #5
Source File: FTPNetworkClient.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public boolean connectClient() throws IOException {
    boolean isLoggedIn = true;
    client.setAutodetectUTF8(true);
    client.setControlEncoding("UTF-8");
    client.connect(host, port);
    client.setFileType(FTP.BINARY_FILE_TYPE);
    client.enterLocalPassiveMode();
    client.login(username, password);
    int reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        client.disconnect();
        LogUtils.LOGD(TAG, "Negative reply form FTP server, aborting, id was {}:"+ reply);
        //throw new IOException("failed to connect to FTP server");
        isLoggedIn = false;
    }
    return isLoggedIn;
}
 
Example #6
Source File: FTPSNetworkClient.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public boolean connectClient() throws IOException {
    boolean isLoggedIn = true;
    client.setAutodetectUTF8(true);
    client.setControlEncoding("UTF-8");
    client.connect(host, port);
    client.setFileType(FTP.BINARY_FILE_TYPE);
    client.enterLocalPassiveMode();
    client.login(username, password);
    int reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        client.disconnect();
        LogUtils.LOGD(TAG, "Negative reply form FTP server, aborting, id was {}:"+ reply);
        //throw new IOException("failed to connect to FTP server");
        isLoggedIn = false;
    }
    return isLoggedIn;
}
 
Example #7
Source File: FTPNetworkClient.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public boolean connectClient() throws IOException {
    boolean isLoggedIn = true;
    client.setAutodetectUTF8(true);
    client.setControlEncoding("UTF-8");
    client.connect(host, port);
    client.setFileType(FTP.BINARY_FILE_TYPE);
    client.enterLocalPassiveMode();
    client.login(username, password);
    int reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        client.disconnect();
        LogUtils.LOGD(TAG, "Negative reply form FTP server, aborting, id was {}:"+ reply);
        //throw new IOException("failed to connect to FTP server");
        isLoggedIn = false;
    }
    return isLoggedIn;
}
 
Example #8
Source File: FTPSNetworkClient.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public boolean connectClient() throws IOException {
    boolean isLoggedIn = true;
    client.setAutodetectUTF8(true);
    client.setControlEncoding("UTF-8");
    client.connect(host, port);
    client.setFileType(FTP.BINARY_FILE_TYPE);
    client.enterLocalPassiveMode();
    client.login(username, password);
    int reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        client.disconnect();
        LogUtils.LOGD(TAG, "Negative reply form FTP server, aborting, id was {}:"+ reply);
        //throw new IOException("failed to connect to FTP server");
        isLoggedIn = false;
    }
    return isLoggedIn;
}
 
Example #9
Source File: FtpUtil.java    From SSM with Apache License 2.0 6 votes vote down vote up
public static boolean uploadPicture(String FTP_HOSTNAME,int FTP_PORT,String FTP_USERNAME,String FTP_PASSWORD,String FTP_REMOTE_PATH,String picName,InputStream fileInputStream)throws IOException {
    //创建一个FtpClient
    FTPClient ftpClient = new FTPClient();
    //连接的ip和端口号
    ftpClient.connect(FTP_HOSTNAME,FTP_PORT);
    //登陆的用户名和密码
    ftpClient.login(FTP_USERNAME,FTP_PASSWORD);
    //将文件转换成输入流
    //修改文件的存放地址
    ftpClient.changeWorkingDirectory(FTP_REMOTE_PATH);
    //设置文件的上传格式
    ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
    //将我们的文件流以什么名字存放
    boolean result = ftpClient.storeFile(picName,fileInputStream);
    //退出
    ftpClient.logout();
    return result;
}
 
Example #10
Source File: NetUtils.java    From ApprovalTests.Java with Apache License 2.0 6 votes vote down vote up
public static void ftpUpload(FTPConfig config, String directory, File file, String remoteFileName)
    throws IOException
{
  FTPClient server = new FTPClient();
  server.connect(config.host, config.port);
  assertValidReplyCode(server.getReplyCode(), server);
  server.login(config.userName, config.password);
  assertValidReplyCode(server.getReplyCode(), server);
  assertValidReplyCode(server.cwd(directory), server);
  server.setFileTransferMode(FTP.BINARY_FILE_TYPE);
  server.setFileType(FTP.BINARY_FILE_TYPE);
  server.storeFile(remoteFileName, new FileInputStream(file));
  assertValidReplyCode(server.getReplyCode(), server);
  server.sendNoOp();
  server.disconnect();
}
 
Example #11
Source File: Ftp.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
private FTPClient getClient() throws SocketException, IOException {
	FTPClient ftp = new FTPClient();
	ftp.addProtocolCommandListener(new PrintCommandListener(
			new PrintWriter(System.out)));
	ftp.setDefaultPort(getPort());
	ftp.connect(getIp());
	int reply = ftp.getReplyCode();
	if (!FTPReply.isPositiveCompletion(reply)) {
		log.warn("FTP server refused connection: {}", getIp());
		ftp.disconnect();
		return null;
	}
	if (!ftp.login(getUsername(), getPassword())) {
		log.warn("FTP server refused login: {}, user: {}", getIp(),
				getUsername());
		ftp.logout();
		ftp.disconnect();
		return null;
	}
	ftp.setControlEncoding(getEncoding());
	ftp.setFileType(FTP.BINARY_FILE_TYPE);
	ftp.enterLocalPassiveMode();
	return ftp;
}
 
Example #12
Source File: FtpServiceImpl.java    From zfile with MIT License 6 votes vote down vote up
@SneakyThrows(IOException.class)
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    host = stringStorageConfigMap.get(StorageConfigConstant.HOST_KEY).getValue();
    port = stringStorageConfigMap.get(StorageConfigConstant.PORT_KEY).getValue();
    username = stringStorageConfigMap.get(StorageConfigConstant.USERNAME_KEY).getValue();
    password = stringStorageConfigMap.get(StorageConfigConstant.PASSWORD_KEY).getValue();
    domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    super.basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    if (Objects.isNull(host) || Objects.isNull(port)) {
        isInitialized = false;
    } else {
        ftp = new Ftp(host, Integer.parseInt(port), username, password, StandardCharsets.UTF_8);
        ftp.getClient().configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX));
        ftp.getClient().type(FTP.BINARY_FILE_TYPE);
        testConnection();
        isInitialized = true;
    }
}
 
Example #13
Source File: FtpClientService.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
public void upLoadFile(File uploadFile) throws BrokerException {
    if (!this.ftpClient.isConnected() || !this.ftpClient.isAvailable()) {
        log.error("ftp client not connected to a server");
        throw new BrokerException(ErrorCode.FTP_CLIENT_NOT_CONNECT_TO_SERVER);
    }
    if (!uploadFile.exists()) {
        log.error("upload file not exist");
        throw new BrokerException(ErrorCode.FTP_NOT_EXIST_PATH);
    }

    try {
        this.ftpClient.setDataTimeout(300 * 1000);
        this.ftpClient.enterLocalPassiveMode();
        this.ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

        if (uploadFile.isDirectory()) {
            log.error("it's not a file");
            throw new BrokerException(ErrorCode.FTP_NOT_FILE);
        }

        FileInputStream inputStream = new FileInputStream(uploadFile);
        this.ftpClient.storeFile(uploadFile.getName(), inputStream);
        inputStream.close();
        log.info("file upload success, file name: {}", uploadFile.getName());
    } catch (IOException e) {
        throw new BrokerException(e.getMessage());
    }
}
 
Example #14
Source File: FtpFileMoverTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Test
public void test_calling_create_And_Change_To_Directory() throws IOException {
    Mockery mockContext = constructMockContext();

    final FTPClient mockedFtpClient = mockContext.mock(FTPClient.class);
    final FtpClientFactory mockedFactory = mockContext.mock(FtpClientFactory.class);
    final String directoryName = "directoryName";

    mockContext.checking(new Expectations() {
        {
            one(mockedFactory).createInstance();
            will(returnValue(mockedFtpClient));

            one(mockedFtpClient).connect(with(any(String.class)));
            one(mockedFtpClient).user(with(any(String.class)));
            will(returnValue(1));

            one(mockedFtpClient).pass(with(any(String.class)));
            one(mockedFtpClient).setFileType(FTP.BINARY_FILE_TYPE);

            one(mockedFtpClient).makeDirectory(directoryName);
            will(returnValue(true));

            one(mockedFtpClient).changeWorkingDirectory(directoryName);
        }
    });

    WctDepositParameter depositParameter = new WctDepositParameter();

    FtpFileMover ftpFileMover = new FtpFileMover(mockedFactory);
    ftpFileMover.connect(depositParameter);

    ftpFileMover.createAndChangeToDirectory(directoryName);

    mockContext.assertIsSatisfied();
}
 
Example #15
Source File: FTPFileSystem.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(URI uri, Configuration conf) throws IOException { // get
  super.initialize(uri, conf);
  // get host information from uri (overrides info in conf)
  String host = uri.getHost();
  host = (host == null) ? conf.get(FS_FTP_HOST, null) : host;
  if (host == null) {
    throw new IOException("Invalid host specified");
  }
  conf.set(FS_FTP_HOST, host);

  // get port information from uri, (overrides info in conf)
  int port = uri.getPort();
  port = (port == -1) ? FTP.DEFAULT_PORT : port;
  conf.setInt("fs.ftp.host.port", port);

  // get user/password information from URI (overrides info in conf)
  String userAndPassword = uri.getUserInfo();
  if (userAndPassword == null) {
    userAndPassword = (conf.get("fs.ftp.user." + host, null) + ":" + conf
        .get("fs.ftp.password." + host, null));
  }
  String[] userPasswdInfo = userAndPassword.split(":");
  Preconditions.checkState(userPasswdInfo.length > 1,
                           "Invalid username / password");
  conf.set(FS_FTP_USER_PREFIX + host, userPasswdInfo[0]);
  conf.set(FS_FTP_PASSWORD_PREFIX + host, userPasswdInfo[1]);
  setConf(conf);
  this.uri = uri;
}
 
Example #16
Source File: FTPUtils.java    From TranskribusCore with GNU General Public License v3.0 5 votes vote down vote up
public void uploadFile(String directory, File sourceFile, FTPUploadListener uploadL) throws IOException, InterruptedException {
	try (InputStream is = new BufferedInputStream(new FileInputStream(sourceFile))) {
		setFileType(FTP.BINARY_FILE_TYPE);
		enterLocalPassiveMode();
		setCopyStreamListener(uploadL);
		uploadL.setInputStream(is);
		
		boolean success = true;
		directory = FilenameUtils.normalizeNoEndSeparator(directory);
		if(directory != null && !directory.isEmpty()){
			success = changeWorkingDirectory(directory + "/");
			
			logger.info(success ? "Changed dir to " + printWorkingDirectory() : "Could not change dir to: " + directory);
		}
		if(success){
			success = storeFile(sourceFile.getName(), is);
		}
		
		if (!success) {
			throw new IOException("Error while uploading " + sourceFile.getName());
		} else if (uploadL.isCanceled()) {
			throw new InterruptedException("Upload cancelled!");
		} else {
			uploadL.uploaded(100);
		}

		logout();
	} catch (IOException e) {
		throw e;
	}
}
 
Example #17
Source File: FTPUploader.java    From journaldev with MIT License 5 votes vote down vote up
public FTPUploader(String host, String user, String pwd) throws Exception{
	ftp = new FTPClient();
	ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
	int reply;
	ftp.connect(host);
	reply = ftp.getReplyCode();
	if (!FTPReply.isPositiveCompletion(reply)) {
		ftp.disconnect();
		throw new Exception("Exception in connecting to FTP Server");
	}
	ftp.login(user, pwd);
	ftp.setFileType(FTP.BINARY_FILE_TYPE);
	ftp.enterLocalPassiveMode();
}
 
Example #18
Source File: FTPDownloader.java    From journaldev with MIT License 5 votes vote down vote up
public FTPDownloader(String host, String user, String pwd) throws Exception {
    ftp = new FTPClient();
    ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
    int reply;
    ftp.connect(host);
    reply = ftp.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        ftp.disconnect();
        throw new Exception("Exception in connecting to FTP Server");
    }
    ftp.login(user, pwd);
    ftp.setFileType(FTP.BINARY_FILE_TYPE);
    ftp.enterLocalPassiveMode();
}
 
Example #19
Source File: FtpLogs.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
private void sendFiles() throws SocketException, IOException {
		ftpClient.connect(server, port);
		Log.println("Connected to " + server + ".");
	    Log.print(ftpClient.getReplyString());
	    int reply = ftpClient.getReplyCode();
	    if(!FTPReply.isPositiveCompletion(reply)) {
	    	  ftpClient.disconnect();
	        Log.println("FTP server refused connection.");
	    } else {
	    	ftpClient.login(user, pass);
	    	Log.println("Logging in..");
	    	Log.print(ftpClient.getReplyString());

	    	ftpClient.enterLocalPassiveMode();	
	    	ftpClient.setControlKeepAliveTimeout(300); // set timeout to 5 minutes.  Send NOOPs to keep control channel alive
	    	
	    	ftpClient.setFileType(FTP.ASCII_FILE_TYPE);
	    	
	    	/**
	    	 * This is currently disabled because the payload store changed.  We probablly only want to send for one
	    	 * satellite as this is only used for debugging
	    	 * 
	    	sendFile(PayloadStore.RT_LOG);
	    	sendFile(PayloadStore.MAX_LOG);
	    	sendFile(PayloadStore.MIN_LOG);
	    	sendFile(PayloadStore.RAD_LOG);
*/
	    	ftpClient.disconnect();
	    }
	}
 
Example #20
Source File: FTPFileSystem.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(URI uri, Configuration conf) throws IOException { // get
  super.initialize(uri, conf);
  // get host information from uri (overrides info in conf)
  String host = uri.getHost();
  host = (host == null) ? conf.get("fs.ftp.host", null) : host;
  if (host == null) {
    throw new IOException("Invalid host specified");
  }
  conf.set("fs.ftp.host", host);

  // get port information from uri, (overrides info in conf)
  int port = uri.getPort();
  port = (port == -1) ? FTP.DEFAULT_PORT : port;
  conf.setInt("fs.ftp.host.port", port);

  // get user/password information from URI (overrides info in conf)
  String userAndPassword = uri.getUserInfo();
  if (userAndPassword == null) {
    userAndPassword = (conf.get("fs.ftp.user." + host, null) + ":" + conf
        .get("fs.ftp.password." + host, null));
    if (userAndPassword == null) {
      throw new IOException("Invalid user/passsword specified");
    }
  }
  String[] userPasswdInfo = userAndPassword.split(":");
  conf.set("fs.ftp.user." + host, userPasswdInfo[0]);
  if (userPasswdInfo.length > 1) {
    conf.set("fs.ftp.password." + host, userPasswdInfo[1]);
  } else {
    conf.set("fs.ftp.password." + host, null);
  }
  setConf(conf);
  this.uri = uri;
}
 
Example #21
Source File: FTPFileSystem.java    From RDFS with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(URI uri, Configuration conf) throws IOException { // get
  super.initialize(uri, conf);
  // get host information from uri (overrides info in conf)
  String host = uri.getHost();
  host = (host == null) ? conf.get("fs.ftp.host", null) : host;
  if (host == null) {
    throw new IOException("Invalid host specified");
  }
  conf.set("fs.ftp.host", host);

  // get port information from uri, (overrides info in conf)
  int port = uri.getPort();
  port = (port == -1) ? FTP.DEFAULT_PORT : port;
  conf.setInt("fs.ftp.host.port", port);

  // get user/password information from URI (overrides info in conf)
  String userAndPassword = uri.getUserInfo();
  if (userAndPassword == null) {
    userAndPassword = (conf.get("fs.ftp.user." + host, null) + ":" + conf
        .get("fs.ftp.password." + host, null));
    if (userAndPassword == null) {
      throw new IOException("Invalid user/passsword specified");
    }
  }
  String[] userPasswdInfo = userAndPassword.split(":");
  conf.set("fs.ftp.user." + host, userPasswdInfo[0]);
  if (userPasswdInfo.length > 1) {
    conf.set("fs.ftp.password." + host, userPasswdInfo[1]);
  } else {
    conf.set("fs.ftp.password." + host, null);
  }
  setConf(conf);
  this.uri = uri;
}
 
Example #22
Source File: FtpFileMoverTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Test
public void test_close_disconnects_from_server() throws IOException {
    Mockery mockContext = constructMockContext();

    final FTPClient mockedFtpClient = mockContext.mock(FTPClient.class);
    final FtpClientFactory mockedFactory = mockContext.mock(FtpClientFactory.class);
    final WctDepositParameter depositParameter = new WctDepositParameter();

    mockContext.checking(new Expectations() {
        {
            one(mockedFactory).createInstance();
            will(returnValue(mockedFtpClient));

            one(mockedFtpClient).connect(with(any(String.class)));
            one(mockedFtpClient).user(with(any(String.class)));
            will(returnValue(1));

            one(mockedFtpClient).pass(with(any(String.class)));
            one(mockedFtpClient).setFileType(FTP.BINARY_FILE_TYPE);

            one(mockedFtpClient).disconnect();
        }
    });

    FtpFileMover ftpFileMover = new FtpFileMover(mockedFactory);
    ftpFileMover.connect(depositParameter);

    ftpFileMover.close();

    mockContext.assertIsSatisfied();
}
 
Example #23
Source File: RomLoader.java    From zxpoly with GNU General Public License v3.0 5 votes vote down vote up
static byte[] loadFTPArchive(final String host, final String path, final String name,
                             final String password) throws IOException {
  final FTPClient client = new FTPClient();
  client.connect(host);
  int replyCode = client.getReplyCode();

  if (FTPReply.isPositiveCompletion(replyCode)) {
    try {
      client.login(name == null ? "" : name, password == null ? "" : password);
      client.setFileType(FTP.BINARY_FILE_TYPE);
      client.enterLocalPassiveMode();

      final ByteArrayOutputStream out = new ByteArrayOutputStream(300000);
      if (client.retrieveFile(path, out)) {
        return out.toByteArray();
      } else {
        throw new IOException(
            "Can't load file 'ftp://" + host + path + "\' status=" + client.getReplyCode());
      }
    } finally {
      client.disconnect();
    }
  } else {
    client.disconnect();
    throw new IOException("Can't connect to ftp '" + host + "'");
  }
}
 
Example #24
Source File: InterruptibleUploadProcess.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
private int detectType(String name) {
  if (ourKnownAsciiExts.contains(getExtension(name))) {
    return FTP.ASCII_FILE_TYPE;
  } else {
    return FTP.BINARY_FILE_TYPE;
  }
}
 
Example #25
Source File: Storeftp.java    From openprodoc with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 *
 * @throws PDException
 */
protected void Connect() throws PDException
{
try {
ftpCon.connect(getServer());
ftpCon.login(getUser(), getPassword());
if (getParam()!=null && getParam().length()!=0)
   ftpCon.changeWorkingDirectory(getParam());
ftpCon.setFileType(FTP.BINARY_FILE_TYPE);
} catch (Exception ex)
    {
    PDException.GenPDException("Error_connecting_to_ftp",ex.getLocalizedMessage());
    }
}
 
Example #26
Source File: AbstractFTPInputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
public AbstractFTPInputOperator()
{
  super();
  port = FTP.DEFAULT_PORT;
  userName = "anonymous";
  password = "guest";
}
 
Example #27
Source File: Client.java    From anthelion with Apache License 2.0 5 votes vote down vote up
private void __initDefaults()
{
    __passiveHost        = null;
    __passivePort        = -1;
    __fileType           = FTP.ASCII_FILE_TYPE;
    __fileFormat         = FTP.NON_PRINT_TEXT_FORMAT;
    __systemName         = null;
    __entryParser        = null;
}
 
Example #28
Source File: FtpFileMover.java    From webcurator with Apache License 2.0 5 votes vote down vote up
public void connect(WctDepositParameter depositParameter) {
    try {
        this.ftpClient = ftpClientFactory.createInstance();

        ftpClient.connect(depositParameter.getFtpHost());
        ftpClient.user(depositParameter.getFtpUserName());
        ftpClient.pass(depositParameter.getFtpPassword());
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
    }
    catch (IOException ioe) {
        throw new RuntimeException("Failed to open connection to FTP server: " + depositParameter.getFtpHost(), ioe);
    }

}
 
Example #29
Source File: FtpFileMoverTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Test
public void test_connect() throws IOException {
    Mockery mockContext = constructMockContext();

    final FTPClient mockedFtpClient = mockContext.mock(FTPClient.class);
    final FtpClientFactory mockedFactory = mockContext.mock(FtpClientFactory.class);

    mockContext.checking(new Expectations() {
        {
            one(mockedFactory).createInstance();
            will(returnValue(mockedFtpClient));

            one(mockedFtpClient).connect(with(any(String.class)));
            one(mockedFtpClient).user(with(any(String.class)));
            will(returnValue(1));

            one(mockedFtpClient).pass(with(any(String.class)));
            one(mockedFtpClient).setFileType(FTP.BINARY_FILE_TYPE);
        }
    });

    WctDepositParameter depositParameter = new WctDepositParameter();
    FtpFileMover ftpFileMover = new FtpFileMover(mockedFactory);
    ftpFileMover.connect(depositParameter);

    mockContext.assertIsSatisfied();
}
 
Example #30
Source File: FtpFileMoverTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Test
public void test_store_file() throws IOException {
    Mockery mockContext = constructMockContext();

    final FTPClient mockedFtpClient = mockContext.mock(FTPClient.class);
    final FtpClientFactory mockedFactory = mockContext.mock(FtpClientFactory.class);
    final String fileName = "directoryName";
    final InputStream stream = new ByteArrayInputStream(fileName.getBytes());

    final WctDepositParameter depositParameter = new WctDepositParameter();

    mockContext.checking(new Expectations() {
        {
            one(mockedFactory).createInstance();
            will(returnValue(mockedFtpClient));

            one(mockedFtpClient).connect(with(any(String.class)));
            one(mockedFtpClient).user(with(any(String.class)));
            will(returnValue(1));

            one(mockedFtpClient).pass(with(any(String.class)));
            one(mockedFtpClient).setFileType(FTP.BINARY_FILE_TYPE);

            one(mockedFtpClient).storeFile(fileName, stream);
            will(returnValue(true));

        }
    });

    FtpFileMover ftpFileMover = new FtpFileMover(mockedFactory);
    ftpFileMover.connect(depositParameter);

    ftpFileMover.storeFile(fileName, stream);

    mockContext.assertIsSatisfied();
}