Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FTP Homogenize model #407

Merged
merged 1 commit into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
package akka.stream.alpakka.ftp.impl

import akka.stream.alpakka.ftp.FtpCredentials.{AnonFtpCredentials, NonAnonFtpCredentials}
import akka.stream.alpakka.ftp.{FtpFileSettings, RemoteFileSettings, SftpSettings}
import akka.stream.alpakka.ftp.RemoteFileSettings._
import akka.stream.alpakka.ftp.{FtpFileSettings, FtpSettings, FtpsSettings, RemoteFileSettings, SftpSettings}
import net.schmizz.sshj.SSHClient
import org.apache.commons.net.ftp.FTPClient
import java.net.InetAddress
Expand Down Expand Up @@ -109,7 +108,7 @@ private[ftp] trait FtpDefaultSettings {
): FtpSettings =
FtpSettings(
InetAddress.getByName(hostname),
DefaultFtpPort,
FtpSettings.DefaultFtpPort,
if (username.isDefined)
NonAnonFtpCredentials(username.get, password.getOrElse(""))
else
Expand All @@ -125,7 +124,7 @@ private[ftp] trait FtpsDefaultSettings {
): FtpsSettings =
FtpsSettings(
InetAddress.getByName(hostname),
DefaultFtpsPort,
FtpsSettings.DefaultFtpsPort,
if (username.isDefined)
NonAnonFtpCredentials(username.get, password.getOrElse(""))
else
Expand All @@ -141,7 +140,7 @@ private[ftp] trait SftpDefaultSettings {
): SftpSettings =
SftpSettings(
InetAddress.getByName(hostname),
DefaultSftpPort,
SftpSettings.DefaultSftpPort,
if (username.isDefined)
NonAnonFtpCredentials(username.get, password.getOrElse(""))
else
Expand Down
116 changes: 74 additions & 42 deletions ftp/src/main/scala/akka/stream/alpakka/ftp/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,51 +46,82 @@ sealed abstract class FtpFileSettings extends RemoteFileSettings {
def passiveMode: Boolean
}

object RemoteFileSettings {
/**
* FTP settings
*
* @param host host
* @param port port
* @param credentials credentials (username and password)
* @param binary specifies the file transfer mode, BINARY or ASCII. Default is ASCII (false)
* @param passiveMode specifies whether to use passive mode connections. Default is active mode (false)
*/
final case class FtpSettings(
host: InetAddress,
port: Int = FtpSettings.DefaultFtpPort,
credentials: FtpCredentials = AnonFtpCredentials,
binary: Boolean = false,
passiveMode: Boolean = false
) extends FtpFileSettings {
def withPort(port: Int): FtpSettings =
copy(port = port)

def withCredentials(credentials: FtpCredentials): FtpSettings =
copy(credentials = credentials)

def withBinary(binary: Boolean): FtpSettings =
copy(binary = binary)

def withPassiveMode(passiveMode: Boolean): FtpSettings =
copy(passiveMode = passiveMode)
}

object FtpSettings {

/** Default FTP port */
final val DefaultFtpPort = 21

/** Default FTPs port */
final val DefaultFtpsPort = 2222
/** Java API */
def create(host: InetAddress): FtpSettings =
FtpSettings(host)
}

/** Default SFTP port */
final val DefaultSftpPort = 22
/**
* FTPs settings
*
* @param host host
* @param port port
* @param credentials credentials (username and password)
* @param binary specifies the file transfer mode, BINARY or ASCII. Default is ASCII (false)
* @param passiveMode specifies whether to use passive mode connections. Default is active mode (false)
*/
final case class FtpsSettings(
host: InetAddress,
port: Int = FtpsSettings.DefaultFtpsPort,
credentials: FtpCredentials = AnonFtpCredentials,
binary: Boolean = false,
passiveMode: Boolean = false
) extends FtpFileSettings {
def withPort(port: Int): FtpsSettings =
copy(port = port)

/**
* FTP settings
*
* @param host host
* @param port port
* @param credentials credentials (username and password)
* @param binary specifies the file transfer mode, BINARY or ASCII. Default is ASCII (false)
* @param passiveMode specifies whether to use passive mode connections. Default is active mode (false)
*/
final case class FtpSettings(
host: InetAddress,
port: Int = DefaultFtpPort,
credentials: FtpCredentials = AnonFtpCredentials,
binary: Boolean = false,
passiveMode: Boolean = false
) extends FtpFileSettings
def withCredentials(credentials: FtpCredentials): FtpsSettings =
copy(credentials = credentials)

/**
* FTPs settings
*
* @param host host
* @param port port
* @param credentials credentials (username and password)
* @param binary specifies the file transfer mode, BINARY or ASCII. Default is ASCII (false)
* @param passiveMode specifies whether to use passive mode connections. Default is active mode (false)
*/
final case class FtpsSettings(
host: InetAddress,
port: Int = DefaultFtpsPort,
credentials: FtpCredentials = AnonFtpCredentials,
binary: Boolean = false,
passiveMode: Boolean = false
) extends FtpFileSettings
def withBinary(binary: Boolean): FtpsSettings =
copy(binary = binary)

def withPassiveMode(passiveMode: Boolean): FtpsSettings =
copy(passiveMode = passiveMode)
}

object FtpsSettings {

/** Default FTPs port */
final val DefaultFtpsPort = 2222

/** Java API */
def create(host: InetAddress): FtpsSettings =
FtpsSettings(host)
}

/**
Expand All @@ -104,7 +135,7 @@ object RemoteFileSettings {
*/
final case class SftpSettings(
host: InetAddress,
port: Int = RemoteFileSettings.DefaultSftpPort,
port: Int = SftpSettings.DefaultSftpPort,
credentials: FtpCredentials = AnonFtpCredentials,
strictHostKeyChecking: Boolean = true,
knownHosts: Option[String] = None,
Expand All @@ -127,12 +158,13 @@ final case class SftpSettings(
}

object SftpSettings {
def create(host: InetAddress): SftpSettings =
SftpSettings(host)

def createEmptyIdentity(): Option[SftpIdentity] = None
/** Default SFTP port */
final val DefaultSftpPort = 22

def createEmptyKnownHosts(): Option[String] = None
/** Java API */
def create(host: InetAddress): SftpSettings =
SftpSettings(host)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import akka.NotUsed;
import akka.stream.IOResult;
import akka.stream.alpakka.ftp.RemoteFileSettings.FtpSettings;
import akka.stream.alpakka.ftp.javadsl.Ftp;
import akka.stream.javadsl.Sink;
import akka.stream.javadsl.Source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import akka.NotUsed;
import akka.stream.IOResult;
import akka.stream.alpakka.ftp.RemoteFileSettings.FtpsSettings;
import akka.stream.alpakka.ftp.javadsl.Ftps;
import akka.stream.javadsl.Sink;
import akka.stream.javadsl.Source;
Expand Down
2 changes: 0 additions & 2 deletions ftp/src/test/scala/akka/stream/alpakka/ftp/BaseFtpSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ package akka.stream.alpakka.ftp
import akka.NotUsed
import akka.stream.IOResult
import akka.stream.scaladsl.{Sink, Source}
import akka.stream.alpakka.ftp.RemoteFileSettings.FtpSettings
import akka.stream.alpakka.ftp.FtpCredentials.AnonFtpCredentials
import akka.stream.alpakka.ftp.scaladsl.Ftp
import akka.util.ByteString

import scala.concurrent.Future
import java.net.InetAddress

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package akka.stream.alpakka.ftp

import akka.NotUsed
import akka.stream.alpakka.ftp.RemoteFileSettings.FtpsSettings
import akka.stream.alpakka.ftp.FtpCredentials.AnonFtpCredentials
import akka.stream.alpakka.ftp.scaladsl.Ftps
import akka.stream.IOResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ trait CommonFtpStageSpec extends BaseSpec with Eventually {
implicit val system = getSystem
implicit val mat = getMaterializer
implicit val defaultPatience =
PatienceConfig(timeout = Span(10, Seconds), interval = Span(300, Millis))
PatienceConfig(timeout = Span(30, Seconds), interval = Span(600, Millis))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be wise, I've seen timeouts as well. Are those actually to be expected? Do we know why those are so slow?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raboof I don't know why they're so slow on Travis. Of course, it has to do with the fact that these tests need to start and stop FTP servers but we should do fine tuning on these instances in order to configure the servers properly for working on Travis builds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I've seen tests be quite slow on my local machine at times as well - but haven't taken the time to really dig into that yet.


"FtpBrowserSource" should {
"list all files from root" in {
Expand Down