I've been working on a site to allow clients to sftp data files to us (using SharpSSH.dll) My solution works fine on my development machine but as soon as I move it to production server I am unable to upload.
I know that the problem is because my code is trying to pick up a file on the server when it obviously doesn't exist there so I need some pointers on the best way to resolve this - i.e. how do I adjust my code to allow for an sftp upload from the client machine?
The plan is basically to (and im not entirely sure that I am going about this the correct way) use my web server as a go-between so the client logs on and sftps a file to another server. Advice and pointers are very welcomed - please see code below:
transfer = New SecureFileTransfer("IP", "PORT", "NAME", "PASSWORD")
If transfer.putFile(FileUpload.PostedFile.FileName, company & "/" & filename) = True Then
lblMsg.Text = "File upload complete!"
'write data file details to table
writeAudit()
'check which account manager to alert and send email notification
emailNotify()
Else
lblMsg.Text = "File upload has failed - please try again..."
Exit Sub
End If
Public Sub New(ByVal hostname As String, ByVal port As Integer, ByVal username As String, ByVal password As String)
Me._hostname = hostname
Me._port = port
Me._username = username
Me._password = password
End Sub
Public Function putFile(ByVal localFile As String, ByVal remotePath As String) As Boolean
Try
transfer = New Sftp(Me._hostname, Me._username, Me._password)
transfer.Connect(Me._port)
transfer.Put(localFile, remotePath)
transfer.Close()
Return True
Catch ex As Exception
Dim objWriter As New System.IO.StreamWriter("C:\logfile.txt")
objWriter.Write(ex.Message)
objWriter.Close()
Return False
End Try
End Function
I have checked my sftp credentials and made sure that access from my web server to sftp server is valid and working. My log file is giving me the following exception message:
Could not find file 'c:\windows\system32\inetsrv\x.txt'.
I think I may be misunderstanding how the FileUpload control works here which may well be the crux of the problem
I'm not sure what the exact problem is but I would say that if you have tested your code and are happy it works, then this is not first place to start looking for problems. I would start with the configuration of the FTP server.
Hope this helps!
Related
I have a shared folder containing a list of wav files i wish to open this files from my asp.net application.
everything is working good when we launch our application from loaclhost but after deploying it it is not workin ( it can not find files)
my code :
Dim oDirectories As String() = Directory.GetFiles("\\192.168.1.160\records\Files\" & dateC & "\", "*.wav")
Dim files As List(Of String) = (From q In oDirectories
Where q.Contains(indice)
Select q).ToList()
Dim liststrings As Integer = files.Count
ListBox1.DataSource = files
ListBox1.DataBind()
When you saying "deploying" - what do you actually mean - to a public/hosting server? Realize that you are using a private IP - which in, and of itself, doesn't always point to the problem (it's possible, depending on your type of hosting account - re: dedicated subnet), but based on the info you provided, that would be where to look first.
Good day,
I don't seem to find the solution to this problem, maybe by the lack of knowledge to express what I'm looking for.
I'm doing a SQL connection on ASP.Net on Visual.Net 2012, but everytime I try to connect to the SQL Database, it seems to grab my PC name instead of the username I am specifying on the Connection string. I got direct access to the server in-case it is server side problems. Here is a piece of my code.
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
conexion = New MySqlConnection
cadena = "Server=192.168.17.108;User id=root;Database=testing;Password=!Server2013"
conexion.ConnectionString = cadena
End Sub
It is a local server for testing forms, I don't think it is important to hide user/password.
Thanks for your attention!
Edit: Forgot to mention that it is running on a IIS7 on Windows Server 2008
I think you have a dodgy connect string. Take a look at this site: http://www.connectionstrings.com/mysql/ and you'll see that for mysql the connect string is more like:
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
So UID not 'user id', and Pwd not 'Password'
Hence, assuming all else is correct you should use:
Server=192.168.17.108;Uid=root;Database=testing;Pwd=!Server2013
I've set it to Localhost and it worked,(GENIUS), because the app was running on the server. Thanks Cameron Tinker.
And DaveRlz answer also worked to fix my connection string,
Thanks for the replies.
I am trying to send an email in classic asp site with an attachment. I am recieving the error "The process cannot access the file because it is being used by another process. "
The file is sitting in a shared folder on the same physical server that is hosting the site. If I check in computer management on the server I can confirm that a user has it open.
My question then is: Am I able to send a copy of the file that is saved to disk using cdo.message if that file is in use? I stripped away the rest of my code to do a test and I was still getting the same error using this.
'Create the Message Object
Set objMsg = Server.CreateObject("CDO.Message")
'Set the properties of the Message
With objMsg
Set .Configuration = cdoConfig
.From = sFrom
.To = sTo
.Subject = sSubject
.TextBody = sBody
.Send
End With
No you can't circumvent this restriction nor would you want to else you could be sending a corrupt file.
I have the following code (from msdn) to set file permissions:
' Adds an ACL entry on the specified file for the specified account.
Sub AddFileSecurity(ByVal fileName As String, ByVal account As String, ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)
' Get a FileSecurity object that represents the
' current security settings.
Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)
' Add the FileSystemAccessRule to the security settings.
Dim accessRule As FileSystemAccessRule = New FileSystemAccessRule(account, rights, controlType)
fSecurity.AddAccessRule(accessRule)
' Set the new access settings.
File.SetAccessControl(fileName, fSecurity)
End Sub
I call this using the group IIS_IUSRS (I've tried ComputerName/IIS_IUSRS too) and I'm trying to apply FileSystemRights.FullControl
But results in this error:
System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated
Which suggests IIS_IUSRS doesn't exist (it does). My next step is to output the users and groups on the machine to see what my code thinks does exist. In the mean time does anyone know why, or what is causing this?
This code works fine on my local machine but not when run on my web server. The app pool runs as network service and Network Server has FULL permission on the folder the files are in. I noticed this question that suggests the user needs permission on the directory - but this isn't the problem.
To work around this, change the authentication on the website to run as "Same as app pool" (as opposed to anonymous). Not the best answer, but have tried everything else.
I have an asp.net website that needs to connect to a dBase file on a remote server. The remote server has a ODBC System DSN connection configured but I have no idea how to connect to it.
The ODBC connection on the server won't help you. The ODBC Connection needs to be set up on the machine you want to connect FROM, not the one you want to connect TO.
In order to connect to the DBASE files (and treat them like a database) you will need to
Map a drive so that you can access the location of the files..
Connect use the OleDbConnection.
It ALSO deals with a problem you will have reading DBase files from .NET. If you read them often enough, the app will start throwing a "System.Resources.Exceeded" exception. The only reliable solution I've found has been to kill the app and restart it, which is done in the code named FixMyself. (Not included as it contains sensitive data). The FixMyself routine essentially starts a second exe that kills THIS exe and then restarts it.
The sample code below is copied from production code, and should give you a push int he right direction. it maps the drive, connects, and reads.
It's ugly but it works. It's also only partial as it calls several functions not included here. But again, it should be enough to get you going.
Public Function GetRegisterConnectionString(ByVal PathToFolder As String)
Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & PathToFolder & ";Extended Properties=dBASE IV;User ID=Admin;Password="
End Function
Public Sub ReadMyDbaseFile(ByVal DriveLetter As String, ByVal IPAddress As String)
Dim DpalmPath As String = "\\" & IPAddress & "\c$\Dpalm"
Dim cn As New System.Data.OleDb.OleDbConnection("")
cn.ConnectionString = Me.GetRegisterConnectionString(DpalmPath)
If ds.Tables.Contains("CurrentPrices") Then
ds.Tables.Remove("CurrentPrices")
End If
Dim POSAdapter As New System.Data.OleDb.OleDbDataAdapter("select * From MyDbaseFile WHERE SomeField > 0 AND ACTIVE = -1", cn)
Try
POSAdapter.Fill(ds, "CurrentPrices")
Catch ex As Exception
If InStr(ex.ToString().ToLower(), "system resource exceeded") Then
WriteToLog("System Resource Exceeded Error was thrown on register " & DriveLetter & ", IP " & IPAddress & ".")
Me.FixMyself()
Else
Throw New Exception(ex.ToString())
End If
End Try
ds.Tables("CurrentPrices").Columns.Add("LastModified", GetType(Date))
POSAdapter.Dispose()
POSAdapter = Nothing
cn.Dispose()
cn = Nothing
ds.AcceptChanges()
GC.Collect()
End Sub