Azure Blob To FTP Large Files 20 GG
I want to transfer large files around 20-200 GG from Blob to FTP.
I am using below code to perform the same but getting memory out of exception after the 500 MB is reached.
public void TriggerEfaTrasfer()
string blobConnectionString = ConfigurationManager.AppSettings["BlobConnectionString"];
string blobContainer = ConfigurationManager.AppSettings["FileContainer"];
CloudStorageAccount storageaccount = CloudStorageAccount.Parse(blobConnectionString);
var blobClient = storageaccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(blobContainer);
var blobs = container.ListBlobs();
TransferFilesFromBlobToEfa(blobs);
private void TransferFilesFromBlobToEfa(IEnumerable<IListBlobItem> blobitem)
try
OpenConnection();
foreach (var item in blobitem.Where((blobItem, type) => blobItem is CloudBlockBlob))
UploadFileStream(item as CloudBlockBlob);
// List all additional subdirectories in the current directory, and call recursively:
foreach (var item in blobitem.Where((blobItem, type) => blobItem is CloudBlobDirectory))
var directory = item as CloudBlobDirectory;
Directory.CreateDirectory(directory.Prefix);
TransferFilesFromBlobToEfa(directory.ListBlobs());
catch (Exception ex)
// throw ex.InnerException;
log.Error(ex);
finally
ftpConnection.Close();
private void UploadFileStream(CloudBlockBlob blobFile)
string fileName = Path.GetFileName(blobFile.Name);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + ConfigurationManager.AppSettings["StagingServerHostName"] + "//" + fileName);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["FtpUserName"], ConfigurationManager.AppSettings["FtpPassword"]);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
request.Timeout = 700000;
try
byte chunk = new byte[4000000];
long blobTotalLength = blobFile.Properties.Length;
long totalChunks = (blobTotalLength - 1) / 4000000 + 1;
using (Stream reqStream = request.GetRequestStream())
using (var fileStream = new MemoryStream())
if (totalChunks > 1)
for (int index = 0; index < totalChunks; index++)
try
if (index == 0)
blobFile.DownloadRangeToStream(fileStream, 0, chunk.Length);
reqStream.Write(fileStream.ToArray(), 0, chunk.Length);
//last chunk
else if (index == totalChunks - 1)
long remaningContent = blobTotalLength - (index * 4000000);
blobFile.DownloadRangeToStream(fileStream, index * 4000000, remaningContent);
reqStream.Write(fileStream.ToArray(), index * 4000000, (Int32)remaningContent);
else
blobFile.DownloadRangeToStream(fileStream, index * 4000000, chunk.Length);
reqStream.Write(fileStream.ToArray(), index * 4000000, chunk.Length);
catch (Exception ex)
else
blobFile.DownloadToStream(fileStream);
reqStream.Write(fileStream.ToArray(), 0, fileStream.ToArray().Length);
fileStream.Flush();
fileStream.Close();
reqStream.Flush();
reqStream.Close();
//Gets the FtpWebResponse of the uploading operation
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
log.Warn("Response for " + fileName + " " + response.StatusDescription);
response.Close();
catch (Exception ex)
log.Error(ex);
add a comment |
I want to transfer large files around 20-200 GG from Blob to FTP.
I am using below code to perform the same but getting memory out of exception after the 500 MB is reached.
public void TriggerEfaTrasfer()
string blobConnectionString = ConfigurationManager.AppSettings["BlobConnectionString"];
string blobContainer = ConfigurationManager.AppSettings["FileContainer"];
CloudStorageAccount storageaccount = CloudStorageAccount.Parse(blobConnectionString);
var blobClient = storageaccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(blobContainer);
var blobs = container.ListBlobs();
TransferFilesFromBlobToEfa(blobs);
private void TransferFilesFromBlobToEfa(IEnumerable<IListBlobItem> blobitem)
try
OpenConnection();
foreach (var item in blobitem.Where((blobItem, type) => blobItem is CloudBlockBlob))
UploadFileStream(item as CloudBlockBlob);
// List all additional subdirectories in the current directory, and call recursively:
foreach (var item in blobitem.Where((blobItem, type) => blobItem is CloudBlobDirectory))
var directory = item as CloudBlobDirectory;
Directory.CreateDirectory(directory.Prefix);
TransferFilesFromBlobToEfa(directory.ListBlobs());
catch (Exception ex)
// throw ex.InnerException;
log.Error(ex);
finally
ftpConnection.Close();
private void UploadFileStream(CloudBlockBlob blobFile)
string fileName = Path.GetFileName(blobFile.Name);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + ConfigurationManager.AppSettings["StagingServerHostName"] + "//" + fileName);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["FtpUserName"], ConfigurationManager.AppSettings["FtpPassword"]);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
request.Timeout = 700000;
try
byte chunk = new byte[4000000];
long blobTotalLength = blobFile.Properties.Length;
long totalChunks = (blobTotalLength - 1) / 4000000 + 1;
using (Stream reqStream = request.GetRequestStream())
using (var fileStream = new MemoryStream())
if (totalChunks > 1)
for (int index = 0; index < totalChunks; index++)
try
if (index == 0)
blobFile.DownloadRangeToStream(fileStream, 0, chunk.Length);
reqStream.Write(fileStream.ToArray(), 0, chunk.Length);
//last chunk
else if (index == totalChunks - 1)
long remaningContent = blobTotalLength - (index * 4000000);
blobFile.DownloadRangeToStream(fileStream, index * 4000000, remaningContent);
reqStream.Write(fileStream.ToArray(), index * 4000000, (Int32)remaningContent);
else
blobFile.DownloadRangeToStream(fileStream, index * 4000000, chunk.Length);
reqStream.Write(fileStream.ToArray(), index * 4000000, chunk.Length);
catch (Exception ex)
else
blobFile.DownloadToStream(fileStream);
reqStream.Write(fileStream.ToArray(), 0, fileStream.ToArray().Length);
fileStream.Flush();
fileStream.Close();
reqStream.Flush();
reqStream.Close();
//Gets the FtpWebResponse of the uploading operation
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
log.Warn("Response for " + fileName + " " + response.StatusDescription);
response.Close();
catch (Exception ex)
log.Error(ex);
add a comment |
I want to transfer large files around 20-200 GG from Blob to FTP.
I am using below code to perform the same but getting memory out of exception after the 500 MB is reached.
public void TriggerEfaTrasfer()
string blobConnectionString = ConfigurationManager.AppSettings["BlobConnectionString"];
string blobContainer = ConfigurationManager.AppSettings["FileContainer"];
CloudStorageAccount storageaccount = CloudStorageAccount.Parse(blobConnectionString);
var blobClient = storageaccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(blobContainer);
var blobs = container.ListBlobs();
TransferFilesFromBlobToEfa(blobs);
private void TransferFilesFromBlobToEfa(IEnumerable<IListBlobItem> blobitem)
try
OpenConnection();
foreach (var item in blobitem.Where((blobItem, type) => blobItem is CloudBlockBlob))
UploadFileStream(item as CloudBlockBlob);
// List all additional subdirectories in the current directory, and call recursively:
foreach (var item in blobitem.Where((blobItem, type) => blobItem is CloudBlobDirectory))
var directory = item as CloudBlobDirectory;
Directory.CreateDirectory(directory.Prefix);
TransferFilesFromBlobToEfa(directory.ListBlobs());
catch (Exception ex)
// throw ex.InnerException;
log.Error(ex);
finally
ftpConnection.Close();
private void UploadFileStream(CloudBlockBlob blobFile)
string fileName = Path.GetFileName(blobFile.Name);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + ConfigurationManager.AppSettings["StagingServerHostName"] + "//" + fileName);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["FtpUserName"], ConfigurationManager.AppSettings["FtpPassword"]);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
request.Timeout = 700000;
try
byte chunk = new byte[4000000];
long blobTotalLength = blobFile.Properties.Length;
long totalChunks = (blobTotalLength - 1) / 4000000 + 1;
using (Stream reqStream = request.GetRequestStream())
using (var fileStream = new MemoryStream())
if (totalChunks > 1)
for (int index = 0; index < totalChunks; index++)
try
if (index == 0)
blobFile.DownloadRangeToStream(fileStream, 0, chunk.Length);
reqStream.Write(fileStream.ToArray(), 0, chunk.Length);
//last chunk
else if (index == totalChunks - 1)
long remaningContent = blobTotalLength - (index * 4000000);
blobFile.DownloadRangeToStream(fileStream, index * 4000000, remaningContent);
reqStream.Write(fileStream.ToArray(), index * 4000000, (Int32)remaningContent);
else
blobFile.DownloadRangeToStream(fileStream, index * 4000000, chunk.Length);
reqStream.Write(fileStream.ToArray(), index * 4000000, chunk.Length);
catch (Exception ex)
else
blobFile.DownloadToStream(fileStream);
reqStream.Write(fileStream.ToArray(), 0, fileStream.ToArray().Length);
fileStream.Flush();
fileStream.Close();
reqStream.Flush();
reqStream.Close();
//Gets the FtpWebResponse of the uploading operation
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
log.Warn("Response for " + fileName + " " + response.StatusDescription);
response.Close();
catch (Exception ex)
log.Error(ex);
I want to transfer large files around 20-200 GG from Blob to FTP.
I am using below code to perform the same but getting memory out of exception after the 500 MB is reached.
public void TriggerEfaTrasfer()
string blobConnectionString = ConfigurationManager.AppSettings["BlobConnectionString"];
string blobContainer = ConfigurationManager.AppSettings["FileContainer"];
CloudStorageAccount storageaccount = CloudStorageAccount.Parse(blobConnectionString);
var blobClient = storageaccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(blobContainer);
var blobs = container.ListBlobs();
TransferFilesFromBlobToEfa(blobs);
private void TransferFilesFromBlobToEfa(IEnumerable<IListBlobItem> blobitem)
try
OpenConnection();
foreach (var item in blobitem.Where((blobItem, type) => blobItem is CloudBlockBlob))
UploadFileStream(item as CloudBlockBlob);
// List all additional subdirectories in the current directory, and call recursively:
foreach (var item in blobitem.Where((blobItem, type) => blobItem is CloudBlobDirectory))
var directory = item as CloudBlobDirectory;
Directory.CreateDirectory(directory.Prefix);
TransferFilesFromBlobToEfa(directory.ListBlobs());
catch (Exception ex)
// throw ex.InnerException;
log.Error(ex);
finally
ftpConnection.Close();
private void UploadFileStream(CloudBlockBlob blobFile)
string fileName = Path.GetFileName(blobFile.Name);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + ConfigurationManager.AppSettings["StagingServerHostName"] + "//" + fileName);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["FtpUserName"], ConfigurationManager.AppSettings["FtpPassword"]);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
request.Timeout = 700000;
try
byte chunk = new byte[4000000];
long blobTotalLength = blobFile.Properties.Length;
long totalChunks = (blobTotalLength - 1) / 4000000 + 1;
using (Stream reqStream = request.GetRequestStream())
using (var fileStream = new MemoryStream())
if (totalChunks > 1)
for (int index = 0; index < totalChunks; index++)
try
if (index == 0)
blobFile.DownloadRangeToStream(fileStream, 0, chunk.Length);
reqStream.Write(fileStream.ToArray(), 0, chunk.Length);
//last chunk
else if (index == totalChunks - 1)
long remaningContent = blobTotalLength - (index * 4000000);
blobFile.DownloadRangeToStream(fileStream, index * 4000000, remaningContent);
reqStream.Write(fileStream.ToArray(), index * 4000000, (Int32)remaningContent);
else
blobFile.DownloadRangeToStream(fileStream, index * 4000000, chunk.Length);
reqStream.Write(fileStream.ToArray(), index * 4000000, chunk.Length);
catch (Exception ex)
else
blobFile.DownloadToStream(fileStream);
reqStream.Write(fileStream.ToArray(), 0, fileStream.ToArray().Length);
fileStream.Flush();
fileStream.Close();
reqStream.Flush();
reqStream.Close();
//Gets the FtpWebResponse of the uploading operation
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
log.Warn("Response for " + fileName + " " + response.StatusDescription);
response.Close();
catch (Exception ex)
log.Error(ex);
edited Nov 12 '18 at 12:13
Murray Foxcroft
5,4613352
5,4613352
asked Nov 12 '18 at 12:10
pulkit arorapulkit arora
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
From your description, I think the problem is because the read file is too large. The application read the full file into memory before processing it. You need to split your file into multiple files, then upload to FTP.
I suggest you using BlobURL.download to implement it. Here is the detailed introduction and the sample code. You could also use Fiddler to monitor the whole process. This could help you know which part of them occurs to error.
And you should also notice the FTP upload restriction. About the restriction, you can refer to this article.
If you still have questions, please let me know.
If my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 20 '18 at 6:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261930%2fazure-blob-to-ftp-large-files-20-gg%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
From your description, I think the problem is because the read file is too large. The application read the full file into memory before processing it. You need to split your file into multiple files, then upload to FTP.
I suggest you using BlobURL.download to implement it. Here is the detailed introduction and the sample code. You could also use Fiddler to monitor the whole process. This could help you know which part of them occurs to error.
And you should also notice the FTP upload restriction. About the restriction, you can refer to this article.
If you still have questions, please let me know.
If my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 20 '18 at 6:13
add a comment |
From your description, I think the problem is because the read file is too large. The application read the full file into memory before processing it. You need to split your file into multiple files, then upload to FTP.
I suggest you using BlobURL.download to implement it. Here is the detailed introduction and the sample code. You could also use Fiddler to monitor the whole process. This could help you know which part of them occurs to error.
And you should also notice the FTP upload restriction. About the restriction, you can refer to this article.
If you still have questions, please let me know.
If my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 20 '18 at 6:13
add a comment |
From your description, I think the problem is because the read file is too large. The application read the full file into memory before processing it. You need to split your file into multiple files, then upload to FTP.
I suggest you using BlobURL.download to implement it. Here is the detailed introduction and the sample code. You could also use Fiddler to monitor the whole process. This could help you know which part of them occurs to error.
And you should also notice the FTP upload restriction. About the restriction, you can refer to this article.
If you still have questions, please let me know.
From your description, I think the problem is because the read file is too large. The application read the full file into memory before processing it. You need to split your file into multiple files, then upload to FTP.
I suggest you using BlobURL.download to implement it. Here is the detailed introduction and the sample code. You could also use Fiddler to monitor the whole process. This could help you know which part of them occurs to error.
And you should also notice the FTP upload restriction. About the restriction, you can refer to this article.
If you still have questions, please let me know.
answered Nov 15 '18 at 9:19
George ChenGeorge Chen
54317
54317
If my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 20 '18 at 6:13
add a comment |
If my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 20 '18 at 6:13
If my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 20 '18 at 6:13
If my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 20 '18 at 6:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261930%2fazure-blob-to-ftp-large-files-20-gg%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown