Skip to content

Commit

Permalink
#50 - timeout configuration (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
regis-leray authored May 15, 2020
1 parent 9f47027 commit 2e0fe42
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/scala/ray/fs2/ftp/Ftp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ object Ftp {
ftpClient.setFileType(FTP.BINARY_FILE_TYPE)
}

ftpClient.setConnectTimeout(settings.connectTimeOut)
ftpClient.setDefaultTimeout(settings.timeOut)

if (settings.passiveMode) {
ftpClient.enterLocalPassiveMode()
}
Expand Down
14 changes: 11 additions & 3 deletions src/main/scala/ray/fs2/ftp/FtpSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ object FtpSettings {
sftpIdentity: Option[SftpIdentity],
strictHostKeyChecking: Boolean,
knownHosts: Option[String],
timeOut: Int,
connectTimeOut: Int,
sshConfig: SshConfig
) extends FtpSettings[JSFTPClient]

Expand All @@ -63,6 +65,8 @@ object FtpSettings {
sftpIdentity = None,
strictHostKeyChecking = false,
knownHosts = None,
0,
0,
new DefaultSshConfig()
)

Expand All @@ -74,6 +78,8 @@ object FtpSettings {
sftpIdentity = Some(identity),
strictHostKeyChecking = false,
knownHosts = None,
0,
0,
new DefaultSshConfig()
)
}
Expand All @@ -85,16 +91,18 @@ object FtpSettings {
binary: Boolean,
passiveMode: Boolean,
proxy: Option[Proxy],
secure: Boolean
secure: Boolean,
timeOut: Int,
connectTimeOut: Int
) extends FtpSettings[JFTPClient]

object UnsecureFtpSettings {

def apply(host: String, port: Int, creds: FtpCredentials): UnsecureFtpSettings =
new UnsecureFtpSettings(host, port, creds, true, true, None, false)
new UnsecureFtpSettings(host, port, creds, true, true, None, false, 0, 0)

def secure(host: String, port: Int, creds: FtpCredentials): UnsecureFtpSettings =
new UnsecureFtpSettings(host, port, creds, true, true, None, true)
new UnsecureFtpSettings(host, port, creds, true, true, None, true, 0, 0)
}

}
3 changes: 3 additions & 0 deletions src/main/scala/ray/fs2/ftp/SFtp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ object SFtp {
else
knownHosts.map(new File(_)).foreach(ssh.loadKnownHosts)

ssh.setTimeout(settings.timeOut)
ssh.setConnectTimeout(settings.connectTimeOut)

ssh.connect(host, port)

sftpIdentity
Expand Down

0 comments on commit 2e0fe42

Please sign in to comment.