I want to know the price to purchase a Rebex server used for SFTP Connectivity and can it be used in various machines with a single purchased license.
It must support private key Authentication too. Currently I used a Rebex Server Beta Version that supports the same but it's trial version has expired.
How much price it is required to purchase a Rebex server and can it be used in various machines with a single license?
Answered: Get IP Address of Connected Client?
IP address is not available in FileUploaded
/FileDownloaded
events (yet), but you can work around this by using a custom user class and a custom Authentication
event that associates an IP with a per-session user object.
Try using this custom user class:
public class CustomUser : FileServerUser
{
private readonly string _userName;
private readonly string _password;
private readonly string _virtualRootPath;
public CustomUser(string userName, string password, string virtualRootPath)
: base(userName, password, virtualRootPath)
{
_userName = userName;
_password = password;
_virtualRootPath = virtualRootPath;
}
private class ActiveCustomUser : CustomUser
{
public IPAddress Address { get; private set; }
public ActiveCustomUser(IPAddress address, string userName, string password, string virtualRootPath)
: base(userName, password, virtualRootPath)
{
Address = address;
}
}
public FileServerUser ToActiveUser(IPAddress address)
{
return new ActiveCustomUser(address, _userName, _password, _virtualRootPath);
}
public static IPAddress GetAddress(FileServerUser user)
{
var activeUser = user as ActiveCustomUser;
if (activeUser == null)
return IPAddress.None;
else
return activeUser.Address;
}
}
To make it work, you have to provide Authentication
and FileUploaded
/FileDownloaded
events:
var server = new FileServer();
server.Keys.Add(SshPrivateKey.Generate());
server.Bind(22, FileServerProtocol.Sftp);
server.Users.Add(new CustomUser("user01", "password", @"c:\temp\SftpRoot"));
server.Authentication += (sender, e) =>
{
var user = (CustomUser)e.Users[e.UserName];
if (user.CheckPassword(e.Password))
{
e.Accept(user.ToActiveUser(e.ClientAddress));
return;
}
e.Reject();
};
server.FileUploaded += (sender, e) =>
{
IPAddress address = CustomUser.GetAddress(e.User);
...
};
server.Start();
Rejecting access from unwanted IP addresses is possible in Connecting
event:
server.Connecting += (sender, e) =>
{
e.Accept = IsAllowed(e.ClientAddress);
};
This will still accept the incoming connection, but it will be closed immediately without performing any SSH negotiation. If you prefer rejecting the connection attempts without accepting them first, you would have to do that at the firewall.
Answered: Server IP works for local 127.0.0.1 , but not working for IP address Comcast assigned
Hi,
I assume that most Internet provider these days provide a modem/router to which multiple devices could be connected. In these cases, the local network is using a private IP address range that is not accessible from the Internet, and the router performs network address translation for outgoing connections.
If this is the case, you have to configure the modem/router to forward incoming connections to port 22 (or other) to your SFTP servers's local IP address. This is somewhat beyond the scope of Rebex SFTP support, but there is plenty of information on the web about this. Try this search, for example.
Encrypt content list for Zip file
Hi,
Is there any way to encrypt Zip file content list with your current Rebex.Zip ? Looks like right now only file content is encrypted but someone can still browse the zip file and see files inside even though its encrypted?
Thanks
Answered: Encrypt content list for Zip file
This is part of Strong Encryption Specification (SES) format. Even though we could easily add support for it, we are not allowed to do this because SES is a patented technology and PKWARE refused to grant us a license:
"Regarding your request for a license for the Single Password Symmetric Encryption technology, PKWARE is discontinuing this licensing program and no further licenses will be issued under it. We are unable to grant your request." - PKWARE, Inc.
Sadly, this means we can't add support for ZIP content list encryption. Sorry!
Double-zipping approach you used is the recommended workaround for this, and it's sufficient to only encrypt the second ZIP.
But my enviroment only has one user, we still want to get Client IP
How to get IP of the client in the upload/download event?
Hi all,
We are planning to set up a SCP server and needs to get the client IP when it uploads/downloads files.
It seems that the upload/download evens of the FileServer do not provide the information of the client IPs. In our environment multi clients from different machines can only share the same user name / password to connect to the server (for management reason).
Any workaround to get the client IP? This is a critical requirement for our usage, any help appreciated.
Allison
How much price it is required to purchase a Rebex server and can it be used in various machines with a single license?
I want to know the price to purchase a Rebex server used for SFTP Connectivity and can it be used in various machines with a single purchased license.
It must support private key Authentication too. Currently I used a Rebex Server Beta Version that supports the same but it's trial version has expired.
Help troubleshooting SocketException "An established connection was aborted by the software in your host machine"
We have a scheduled job that retrieves new files from an SFTP server every 20 minutes. About 1 in 200 attempts, the job fails with SocketException: An established connection was aborted by the software in your host machine.
This apparently corresponds to TCP/IP socket error WSAECONNABORTED.
We are trying to determine whether the problem lies in our infrastructure, the remote server, or perhaps in Rebex's SFTP implementation's compatibility with this particular system. We use Rebex SFTP successfully with many other servers with much higher reliability. The remote system is Solaris SSHD and our partner has a lot of traffic so they are unable to enable verbose logging because it would flood their disk. Are there any other techniques we can use to troubleshoot?
A complete example log is below. Note that this error occurs at various times during a session, sometimes during or just after authentication (as below), sometimes while waiting for response to an LS command, or somtimes during a file download.
We have inspected our firewall logs and found no blocking/filtering has occurred (our partner has done so as well and found no blocking/filtering).
When the error occurs we have tried FileZilla within a minute or so with no errors. Retrying about a minute later with RebEx is successful as well.
2016-10-19 06:43:04.165 INFO Sftp(4871)[29] Info: Connecting to xxxx.xxxx.com:1139 using Sftp 3.0.5584.0.
2016-10-19 06:43:04.321 DEBUG Sftp(4871)[29] SSH: Server is 'SSH-2.0-Sun_SSH_1.1.6'.
2016-10-19 06:43:04.321 INFO Sftp(4871)[29] SSH: Negotiation started.
2016-10-19 06:43:04.587 DEBUG Sftp(4871)[29] SSH: Group exchange.
2016-10-19 06:43:04.680 DEBUG Sftp(4871)[29] SSH: Negotiating key.
2016-10-19 06:43:04.821 DEBUG Sftp(4871)[29] SSH: Validating signature.
2016-10-19 06:43:04.821 INFO Sftp(4871)[29] SSH: Negotiation finished.
2016-10-19 06:43:04.821 INFO Sftp(4871)[29] Info: Server: SSH-2.0-Sun_SSH_1.1.6
2016-10-19 06:43:04.821 INFO Sftp(4871)[29] Info: Fingerprint: xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
2016-10-19 06:43:04.821 INFO Sftp(4871)[29] Info: Cipher info: SSH 2.0, DiffieHellmanGroupExchangeSHA1, DSS, aes256- ctr/aes256-ctr, hmac-sha1/hmac-sha1
2016-10-19 06:43:11.321 DEBUG Sftp(4871)[29] SSH: Allowed authentication methods: gssapi-keyex, gssapi-with-mic, publickey, password, keyboard-interactive.
2016-10-19 06:43:11.321 DEBUG Sftp(4871)[29] SSH: Trying password authentication for 'xxxxxxxxxxxxxxxx'.
2016-10-19 06:43:11.587 DEBUG Sftp(4871)[29] SSH: Authentication successful.
2016-10-19 06:43:11.665 ERROR Sftp(4871)[29] SSH: Rebex.Net.SshException: The connection was aborted. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
at Rebex.Net.ProxySocket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at Rebex.Net.SshSession.SY(Int32 A)
--- End of inner exception stack trace ---
at Rebex.Net.SshSession.SY(Int32 A)
at Rebex.Net.SshSession.VY(Byte[]& A)
at Rebex.Net.SshSession.YY(NGB A, Object[] B)
at Rebex.Net.SshSession.OZ(SshChannelType A, Int32 B, Object[] C)
2016-10-19 06:43:11.665 ERROR Sftp(4871)[29] Info: Rebex.Net.SshException: The connection was aborted. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
at Rebex.Net.ProxySocket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at Rebex.Net.SshSession.SY(Int32 A)
--- End of inner exception stack trace ---
at Rebex.Net.SshSession.SY(Int32 A)
at Rebex.Net.SshSession.VY(Byte[]& A)
at Rebex.Net.SshSession.YY(NGB A, Object[] B)
at Rebex.Net.SshSession.OZ(SshChannelType A, Int32 B, Object[] C)
at Rebex.Net.SshSession.OpenChannel(SshChannelType type, Int32 bufferSize)
at Rebex.Net.Sftp.LBB(XMB A)
at Rebex.Net.Sftp.IP(String A, String B, SshPrivateKey C, XMB D)
Answered: But my enviroment only has one user, we still want to get Client IP
The proposed solution will work in single-user scenarios as well.
Answered: How to get IP of the client in the upload/download event?
Hi,
The solution proposed in another answer should be suitable for this scenario as well. Please give it a try and let us know if you run into any problems.
To enable SCP in addition to SFTP, you would have to add the following line as well:
server.Bind(22, FileServerProtocol.Scp);
Answered: In from field of email, your names contains double quote which shows \" instead of "
This From
header is not formatted correctly:
From: "\"atul\" cus't'omer" atcust@ccms.apac.avaya.com
According to RFC 2822, the address must be enclosed in angle brackets when display name is present, which means the header should look like this:
From: "\"atul\" cus't'omer"<atcust@ccms.apac.avaya.com>
.
Please note that \"
is not causing any problems - the backslash just indicates that the following character is a literal character, not a control character. The lack of <
and >
is the problem. (See the examples in RFC 2822.)
Extracting html & embedded image
Hi,
With this code:
var mail = new Rebex.Mail.MailMessage();
mail.Load(@"c:\temp\some-email-with-html-content.eml");
File.WriteAllText(@"c:\temp\some-email-with-html-content.htm", mail.BodyHtml);
I can extract the html but the embedded base64'd images in the .eml file is not saved as embedded images .htm (it's saved as cid:...)
Is there a way to do this ?
Thanks !
passive mode how do i set in code
I am using sftp to connect to a sftp directory but when passive mode is not selected in filezilla i cannot connect and the same goes for when i attempt my normal code which is as below how would one enable the code for passive mode sftp.
The error that i get is the following says username and password incorrect but i no its not as I can connect in filezilla with passive mode being active.
public void sendFileToSftp(string filename, string serverFile, string IVARef, string firstname,string lastname,string hostname, string port, string username, string password)
{
try
{
// create client, connect and log in
Sftp client = new Sftp();
client.Connect(hostname);
client.Login(username, password);
client.TransferProgressChanged += new EventHandler<SftpTransferProgressChangedEventArgs>(sftp_TransferProgressChanged);
client.ChangeDirectory("/Outbound");
client.CreateDirectory(IVARef + "" + firstname + "" + lastname);
// upload the 'test.zip' file to the current directory at the server
client.PutFile(filename, serverFile);
client.Disconnect();
}
catch (Exception ex)
{
string inner = string.Empty;
if (ex.InnerException != null)
{
inner = ex.InnerException.ToString();
}
// logger.Error("Error in GetNotificationById function aperturenetdal " + ex.ToString() + "" + inner);
return "";
}
}
Answered: Extracting html & embedded image
The embedded images are stored in the MailMessage.Resources
collection.
To convert HTML mail to ordinary HTML page, you need to manipulate the HTML mail body. You have to replace cid:ID
with appropriate string. You can either extract embedded images to files and use the filename instead of cid:ID
or embed the image data into HTML page directly like this:
foreach (var res in mail.Resources)
{
if (res.ContentId == null ||
res.MediaType == null ||
!res.MediaType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
continue;
MemoryStream ms = new MemoryStream();
using (var content = res.GetContentStream())
{
content.CopyTo(ms);
}
byte[] data = ms.ToArray();
string cidString = string.Format("cid:{0}", res.ContentId.Id);
string dataString = string.Format("data:{0};base64,{1}", res.MediaType, Convert.ToBase64String(data));
// replace image link (cid:) with image data (data:)
mail.BodyHtml = mail.BodyHtml.Replace(cidString, dataString);
}
Please note, that this code only shows the way, how to do it. To make it robust you should handle letter case and spaces in "cid:" string.
How to create certificate requests?
how can I create SSL Certificates?
tried to secure a simple webserver (like https://forum.rebex.net/2933/how-to-create-a-simple-tls-ssl-server?show=2933#q2933).
in this example, the certificate was given and loaded from file.
How can I create a private Key, create a csr and crt (with their Attibutes) without use of openssl or BouncyCastle C#?
Answered: Public/Private Key Authentication Issue
Hi,
The key generation code is correct, and thee only possible issue in authentication code is the usage of both password and private key authentication - this is possible, but less common that password-only or key-only authentication.
Otherwise, the most likely cause of the failure is that the server actually refuses this key because it has not been associated with the user properly. What does "saved with the user" mean? With Bitvise, it seems it has to be imported.
In any case, it might be useful to rule out an issue in Rebex SFTP - the easiest way to do this is to try connecting and authenticating using PuTTY command-line psftp
utility (get psftp.exe
from PuTTY download page).
It only accepts private keys in .ppk format, which means you have to convert your key first:
SshPrivateKey privateKey = new SshPrivateKey(@"PrivateKey.pri", "password");
privateKey.Save(@"PrivateKey.ppk", "password", SshPrivateKeyFormat.Putty);
Then, try connecting to the server using psftp
with this key:
psftp servername -i PrivateKey.ppk
If this fails as well, it would strongly suggest the problem is at the server.
How to use rebex in a virtual file system in which compressed archives (zipfiles) can be read similar to disk files
I have done this with Xceed where I can load the create a Xceed.FileSystem.Diskfolder with a disk path, and this then yields abstractfile items when iterated.
abstractfile items which are zip, rar, 7z etc files, can be converted to Xceed.Zip.Archives (by passing the abstract file from the diskfolder, or a Xceed.FileSystem.Diskfile object to the class constructor) and this can be iterated to produce abstract files with the same methods and props as those yielded by Xceed.FileSystem.Diskfolder.
Using this approach I can search and read and display my log files with the same code for files on disk and older files stored in compressed archives.
Files in archives can be searched without the need to first expand compressed files to temporary folders....
How to download Linked Resource Images ?
I am trying to download mail from my outlook mail and showing in an HTML page.
My problem is linked images is not showing in the message body.
I already read bellow article
http://forum.rebex.net/6322/how-to-display-inline-images-in-message-body
So I decided to download the linked resource into a physical path and replace the linked content id from message body with physical path.
Is there any way to download linked resource or any other better solution?
How to resume full directory upload?
Using Ftp.Upload Method (FileSet, String, TransferMethod, ActionOnExistingFiles) to nightly backup around 300 files with each around 200 MB.
ftp.Upload(
localPath,
remotePath,
TransferMethod.Copy,
ActionOnExistingFiles.OverwriteAll);
Recently, I'm randomly getting "Timeout exceeded" errors from the FTP server.
I then retry multiple times.
Unfortunately my try…catch…retry
construct is placed around the whole monolitic upload call (see above code).
I.e. when it fails, I do not retry for the currently uploaded file, but instead for the whole set of files.
First, I thought to use the ProblemDetected event, but unfortunately:
- The documentation says it is only supported for the Upload method overload with two parameters (I'm using the 4 parameter overload, see above code).
- In this answer you say that "…For general errors (e.g. networking errors - server closed the connection, invalid arguments, invalid operation exceptions, etc.) we always throw exceptions and we never raise the ProblemDetected event.…".
So it seems I'm unable to resume one single file only.
My question:
Is there any way to resume single file upload errors (even timeout errors) during a multiple file upload call?