Azure Website Writing file to a network Drive - c#

I have a service that I currently run on our local IIS machine that will write a file to a specified directory using the following code:
//Creating the filepath that is needed
string FilePath = FolderPath.Replace("'", "")
+ FileName.Replace("'", "").Replace(" ", "")
.ToString();
//Writing the file to the correct path
File.WriteAllBytes(FilePath, fileTransferDump.FileBinary);
When I change over to an Azure Website how would I make the System write to the file path that I would like to write to.
Basically how do I cause the Azure website to write to a network share. This is just a normal Azure Website.

Azure Websites don't have the ability to write to off-machine resources using traditional windows file shares. Your best bet would be to wrap any of this logic in a custom library that redirects these file writes to Azure Blob Storage instead.

Related

Where the templ files are created in blob triggered azure function?

I am working on an Azure Function application on Windows Azure.
I have created a Blob triggered azure function that creats a file in temp folder. To get the path of temporary folder to create the temporary file I am using following code block:
string TempFolderLocation = Path.GetTempPath();
string TempFileName = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff") + ".txt";
string TempFilePath = Path.Combine(TempFolderLocation, TempFileName);
System.IO.File.WriteAllText(TempFilePath, "This is the time log : " + DateTime.UtcNow.ToString("yyyy.MM.dd HH:mm:ss.fff"));
I get the path "D:\local\Temp\" as result of Path.GetTempPath().
I am not getting any error when above code gates executed But when I take KUDU of my azure function application, there is no files created in folder "D:\local\Temp\".
So my questions are:
Is execution of blob triggered azure function happening at different
location then KUDU?
Is the execution time temp folder is different then the actual?
Where can I see those temp files?
The azure function doesn't share the temp storage with kudu (and there is a legacy flag to force them to share).
Check "Temporary files" section here:
https://github.com/projectkudu/kudu/wiki/Understanding-the-Azure-App-Service-file-system#temporary-files
Another important note is that the Main site and the scm site do not
share temp files. So if you write some files there from your site, you
will not see them from Kudu Console (and vice versa). You can make
them use the same temp space if you disable separation (via
WEBSITE_DISABLE_SCM_SEPARATION). But note that this is a legacy flag,
and its use is not recommended/supported.

How to write to an iSeries FileShare from ASP.Net

I've written an asp.net webapp that writes a file to a location on our iSeries FileShare.
The path looks like this: \IBMServerAddress\Filepath
This code executes perfectly on my local machine, but fails when it's deployed to my (windows) WebServer.
I understand that i may need to do some sort of impersonation to authenticate access to the IFS, but i'm unsure of how to proceed.
Here's the code i'm working with:
string filepath = "\\\\IBMServerAddress\\uploads\\";
public int SaveToDisk(string data, string plant)
{
//code for saving to disk
StreamWriter stream = null;
stream = File.CreateText(filepath + plant + ".txt"); // creating file
stream.Write(data + "\r\n"); //Write data to file
stream.Close();
return 0;
}
Again, this code executes perfectly on my local machine but does not work when deployed to my Windows WebServer - access to filepath is denied.
Thanks for your help.
EDIT: I've tried adding a network account with the same credentials as the IFS user, created a UNC path (iseries)on IIS7 to map the network drive (using the same credentials) - but receive this error:
Access to the path 'iseries\' is denied.
My understanding of Windows in general is that normally services don't have access to standard network shares like a program being run by a user does.
So the first thing would be to see if you can successfully write to a windows file share from the web server.
Assuming that works, you'll need one of two things in order to write to the IBM i share..
1) An IBM i user ID and password that matches the user ID and password the process is being run under
2) A "guest account" configured on IBM i Netserver
http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzahl/rzahlsetnetguestprof.htm
You might have better luck with using Linux/UNIX based Network File System (NFS) which is supported in both Windows and the IBM i.

Download File via Tamir.SharpSSH.Sftp.Get()

I'm trying to download a file using the Tamir SSH library. I'm able to connect to the remote FTP site, upload files to the site, but I'm getting exceptions when trying to download. I've given IIS_IUSRS full control of the local directory as well as ASPNET. I've tested an I'm able to create a text file in the same local directory I'm trying to download to. Any ideas?
string SFTP_HOST = ConfigurationManager.AppSettings["AccentivFtpHost"];
string SFTP_USERNAME = ConfigurationManager.AppSettings["AccentivFtpUsername"];
string SFTP_PASSWORD = ConfigurationManager.AppSettings["AccentivFtpPassword"];
Sftp client = new Sftp(SFTP_HOST, SFTP_USERNAME, SFTP_PASSWORD);
client.Connect(22);
client.Get("test.txt", "c:\\test.txt");
You probably lack a '/' character in the file directory. You may need to put it either in the Get function call before the "test.txt" like "/test.txt" or at the end of your AccentivFtpHost value in the app config file.

FTP virtual paths. How to know real Windows path?

I have shared hosting account on some hosting service provider. So, I can upload pics or something else through FTP. For instance, my ASP .NET binaries are in /mysite.com/www/bin. But how can I set logging to file in my app? I should use real paths for that purpose. I even try just write to current directory, but I can see this log file through FTP. It just writes to some tmp path as I guess, like '' which couldn't be accessed through FTP.
So how can I setup file path for logging?
This is how I try to write to current binaries directory:
using (StreamWriter sw = new StreamWriter(String.Format("{0}{1}{2}", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "\", "log.txt"), true))
{
sw.WriteLine(DateTime.Now.ToString() + ": " + msg);
sw.WriteLine("------------");
sw.Flush();
sw.Close();
}
It write to some long windows path, which I guess it uses for some temporary storing of binaries.
Assuming your question is "I have FTP server running and serving content of "C:\myFTP\" how can I write log files (i.e. from ASP.Net application) to file available via FTP from the server?"
Answer - just write logs to that "C:\myFTP" location (or whatever location your local FTP server is configured to serve.
I solved it myself. You should use HttpContext.Current.Server.MapPath for that.

Upload files to a remote server

I need to upload files from my asp.net (C#) page residing in the web server to a remote server.
I managed to upload files to remote server from localhost using this code:
string serverPath = "\\\\xx.xxx.xx.xx\\Folder\\" + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(serverPath);
But after I published this code to my web server, it stopped working with the error "The network path was not found."
I have looked at a few solutions which suggest using UNC network share and implementing impersonation.
I couldn't figure out how to apply these solutions.
Can someone please give an example, or suggest a simpler solution.
Thanks!!
In FileUpload1.PostedFile.SaveAs(path), path is physical path of file, No Url. You must check:
is Physical folder Exsist?
is You have access to folder?
if answer of both question is true check this code:
string serverPath = #"\\xxx.xxx.xxx.xxx\Folder\";
if (!System.IO.Directory.Exists(serverPath))
System.IO.Directory.CreateDirectory(serverPath);
FileUpload1.PostedFile.SaveAs(serverPath + FileUpload1.FileName);
The account your application runs under must have write permissions to the folder you are trying to upload the file to: \\xx.xxx.xx.xx\Folder\. So you will have to configure the application pool in IIS to run under an account that will have sufficient permissions. Go to the application pool properties in the IIS management console where you will be able to specify an account to be used to run the application. By default it uses a built-in account which won't have any access to shared resources. Take a look at the following article which explains how to do so.
You need a virtual directory on your webserver to upload to. In code you'll have to use Server.Mappath("virtual path") function to get its server path and then save to it.

Categories